Converting LESS to CSS is a three stage process. The incoming file is parsed by lessc_parser into a syntax tree, then it is compiled into another tree representing the CSS structure by lessc. The CSS tree is fed into a formatter, like lessc_formatter which then outputs CSS as a string. During the first compile, all values are *reduced*, which means that their types are brought to the lowest form before being dump as strings. This handles math equations, variable dereferences, and the like. The parse function of lessc is the entry point. In summary: The lessc class creates an intstance of the parser, feeds it LESS code, then transforms the resulting tree to a CSS tree. This class also holds the evaluation context, such as all available mixins and variables at any given time. The lessc_parser class is only concerned with parsing its input. The lessc_formatter takes a CSS tree, and dumps it to a formatted string, handling things like indentation.
示例#1
0
文件: lessc.php 项目: Getbeans/Beans
 protected function to($what, &$out, $until = false, $allowNewline = false)
 {
     if (is_string($allowNewline)) {
         $validChars = $allowNewline;
     } else {
         $validChars = $allowNewline ? "." : "[^\n]";
     }
     if (!$this->match('(' . $validChars . '*?)' . Beans_Lessc::preg_quote($what), $m, !$until)) {
         return false;
     }
     if ($until) {
         $this->count -= strlen($what);
     }
     // give back $what
     $out = $m[1];
     return true;
 }
示例#2
0
 /**
  * Formal CSS, LESS and JS content.
  */
 public function format_content($content)
 {
     if ('style' == $this->compiler['type']) {
         if ('less' == $this->compiler['format']) {
             if (!class_exists('Beans_Lessc')) {
                 require_once BEANS_API_PATH . 'compiler/vendors/lessc.php';
             }
             $less = new Beans_Lessc();
             $content = $less->compile($content);
         }
         if (!_beans_is_compiler_dev_mode()) {
             $content = $this->strip_whitespace($content);
         }
     }
     if ('script' == $this->compiler['type'] && !_beans_is_compiler_dev_mode() && $this->compiler['minify_js']) {
         if (!class_exists('JSMin')) {
             require_once BEANS_API_PATH . 'compiler/vendors/js-minifier.php';
         }
         $js_min = new JSMin($content);
         $content = $js_min->min();
     }
     return $content;
 }