Esempio n. 1
0
 public function compile($env)
 {
     $a = $this->lvalue->compile($env);
     $b = $this->rvalue->compile($env);
     switch ($this->op) {
         case 'and':
             $result = $a && $b;
             break;
         case 'or':
             $result = $a || $b;
             break;
         default:
             if (Less_Parser::is_method($a, 'compare')) {
                 $result = $a->compare($b);
             } elseif (Less_Parser::is_method($b, 'compare')) {
                 $result = $b->compare($a);
             } else {
                 throw new Less_Exception_Compiler('Unable to perform comparison', null, $this->index);
             }
             switch ($result) {
                 case -1:
                     $result = $this->op === '<' || $this->op === '=<' || $this->op === '<=';
                     break;
                 case 0:
                     $result = $this->op === '=' || $this->op === '>=' || $this->op === '=<' || $this->op === '<=';
                     break;
                 case 1:
                     $result = $this->op === '>' || $this->op === '>=';
                     break;
             }
             break;
     }
     return $this->negate ? !$result : $result;
 }
Esempio n. 2
0
 public function compile($env)
 {
     if (Less_Parser::is_method($this->value, 'compile')) {
         return new Less_Tree_Assignment($this->key, $this->value->compile($env));
     }
     return $this;
 }
Esempio n. 3
0
 function visit($nodes)
 {
     if (!is_array($nodes)) {
         $nodes = array($nodes);
     }
     foreach ($nodes as $node) {
         if (!is_object($node)) {
             continue;
         }
         $class = get_class($node);
         $funcName = 'visit' . substr($class, 10);
         //remove 'Less_Tree_' from the class name
         if (method_exists($this, $funcName)) {
             $this->{$funcName}($node);
         }
         $deeper_property = $funcName . 'Deeper';
         if (!isset($this->{$deeper_property}) && Less_Parser::is_method($node, 'accept')) {
             $node->accept($this);
         }
         $funcName = $funcName . "Out";
         if (method_exists($this, $funcName)) {
             $this->{$funcName}($node);
         }
     }
 }
Esempio n. 4
0
 public function compile($env)
 {
     $args = array();
     foreach ($this->args as $a) {
         $args[] = $a->compile($env);
     }
     $name = $this->name;
     if ($name == '%') {
         $name = '_percent';
     } elseif ($name == 'data-uri') {
         $name = 'datauri';
     }
     if (Less_Parser::is_method($env, $name)) {
         // 1.
         try {
             $result = call_user_func_array(array($env, $name), $args);
             if ($result != null) {
                 return $result;
             }
         } catch (Exception $e) {
             throw Less_CompilerException('error evaluating function `' . $this->name . '` ' . $e->getMessage() . ' index: ' . $this->index);
         }
     }
     // 2.
     $temp = array();
     foreach ($args as $a) {
         $temp[] = $a->toCSS($env);
     }
     return new Less_Tree_Anonymous($this->name . "(" . implode(', ', $temp) . ")");
 }
Esempio n. 5
0
 public function toCSS($env)
 {
     $ret = array();
     foreach ($this->value as $e) {
         $ret[] = Less_Parser::is_method($e, 'toCSS') ? $e->toCSS($env) : '';
     }
     return implode(' ', $ret);
 }
Esempio n. 6
0
 function toCSS($env)
 {
     $value = $this->key;
     if ($this->op) {
         $value .= $this->op;
         $value .= Less_Parser::is_method($this->value, 'toCSS') ? $this->value->toCSS($env) : $this->value;
     }
     return '[' . $value . ']';
 }
Esempio n. 7
0
 function compare($x)
 {
     if (!Less_Parser::is_method($x, 'toCSS')) {
         return -1;
     }
     $left = $this->toCSS();
     $right = $x->toCSS();
     if ($left === $right) {
         return 0;
     }
     return $left < $right ? -1 : 1;
 }
Esempio n. 8
0
 public function compile($env)
 {
     $a = $this->operands[0]->compile($env);
     $b = $this->operands[1]->compile($env);
     if ($env->isMathOn()) {
         if ($a instanceof Less_Tree_Dimension && $b instanceof Less_Tree_Color) {
             if ($this->op === '*' || $this->op === '+') {
                 $temp = $b;
                 $b = $a;
                 $a = $temp;
             } else {
                 throw new Less_CompilerError("Operation on an invalid type");
             }
         }
         if (!Less_Parser::is_method($a, 'operate')) {
             throw new Less_CompilerError("Operation on an invalid type");
         }
         return $a->operate($env, $this->op, $b);
     } else {
         return new Less_Tree_Operation($this->op, array($a, $b), $this->isSpaced);
     }
 }
Esempio n. 9
0
 public function compileNested($env)
 {
     $path = array_merge($env->mediaPath, array($this));
     // Extract the media-query conditions separated with `,` (OR).
     foreach ($path as $key => $p) {
         $value = $p->features instanceof Less_Tree_Value ? $p->features->value : $p->features;
         $path[$key] = is_array($value) ? $value : array($value);
     }
     // Trace all permutations to generate the resulting media-query.
     //
     // (a, b and c) with nested (d, e) ->
     //	a and d
     //	a and e
     //	b and c and d
     //	b and c and e
     $permuted = $this->permute($path);
     $expressions = array();
     foreach ($permuted as $path) {
         for ($i = 0, $len = count($path); $i < $len; $i++) {
             $path[$i] = Less_Parser::is_method($path[$i], 'toCSS') ? $path[$i] : new Less_Tree_Anonymous($path[$i]);
         }
         for ($i = count($path) - 1; $i > 0; $i--) {
             array_splice($path, $i, 0, array(new Less_Tree_Anonymous('and')));
         }
         $expressions[] = new Less_Tree_Expression($path);
     }
     $this->features = new Less_Tree_Value($expressions);
     // Fake a tree-node that doesn't output anything.
     return new Less_Tree_Ruleset(array(), array());
 }
Esempio n. 10
0
 /**
  * less.js: tree.mixin.Call.prototype()
  *
  */
 public function compile($env)
 {
     $rules = array();
     $match = false;
     $isOneFound = false;
     $args = array();
     foreach ($this->arguments as $a) {
         $args[] = array('name' => $a['name'], 'value' => $a['value']->compile($env));
     }
     for ($i = 0; $i < count($env->frames); $i++) {
         $mixins = $env->frames[$i]->find($this->selector, null, $env);
         if (!$mixins) {
             continue;
         }
         $isOneFound = true;
         foreach ($mixins as $mixin) {
             $isRecursive = false;
             foreach ($env->frames as $recur_frame) {
                 if (!$mixin instanceof Less_Tree_MixinDefinition) {
                     if (isset($recur_frame->originalRuleset) && $mixin === $recur_frame->originalRuleset || $mixin === $recur_frame) {
                         $isRecursive = true;
                         break;
                     }
                 }
             }
             if ($isRecursive) {
                 continue;
             }
             if ($mixin->matchArgs($args, $env)) {
                 if (!Less_Parser::is_method($mixin, 'matchCondition') || $mixin->matchCondition($args, $env)) {
                     try {
                         $rules = array_merge($rules, $mixin->compile($env, $args, $this->important)->rules);
                     } catch (Exception $e) {
                         //throw new Less_CompilerException($e->getMessage(), $e->index, null, $this->currentFileInfo['filename']);
                         throw new Less_CompilerException($e->getMessage(), null, null, $this->currentFileInfo['filename']);
                     }
                 }
                 $match = true;
             }
         }
         if ($match) {
             return $rules;
         }
     }
     if ($isOneFound) {
         $message = array();
         if ($args) {
             foreach ($args as $a) {
                 $argValue = '';
                 if ($a['name']) {
                     $argValue += $a['name'] + ':';
                 }
                 if (Less_Parser::is_method($a['value'], 'toCSS')) {
                     $argValue += $a['value']->toCSS();
                 } else {
                     $argValue += '???';
                 }
                 $message[] = $argValue;
             }
         }
         $message = implode(', ', $message);
         throw new Less_CompilerException('No matching definition was found for `' . trim($this->selector->toCSS($env)) . '(' . $message . ')', $this->index, null, $this->currentFileInfo['filename']);
     } else {
         throw new Less_CompilerException(trim($this->selector->toCSS($env)) . " is undefined", $this->index);
     }
 }
Esempio n. 11
0
 public function toCSS($env)
 {
     $css = '';
     // The CSS output
     $rules = array();
     // node.Rule instances
     $_rules = array();
     $rulesets = array();
     // node.Ruleset instances
     // Compile rules and rulesets
     foreach ($this->rules as $rule) {
         if (isset($rule->rules) || $rule instanceof Less_Tree_Media) {
             $rulesets[] = $rule->toCSS($env);
         } else {
             if ($rule instanceof Less_Tree_Directive) {
                 $cssValue = $rule->toCSS($env);
                 // Output only the first @charset definition as such - convert the others
                 // to comments in case debug is enabled
                 if ($rule->name === "@charset") {
                     // Only output the debug info together with subsequent @charset definitions
                     // a comment (or @media statement) before the actual @charset directive would
                     // be considered illegal css as it has to be on the first line
                     if ($env->charset) {
                         continue;
                     }
                     $env->charset = true;
                 }
                 $rulesets[] = $cssValue;
             } else {
                 if ($rule instanceof Less_Tree_Comment) {
                     if (!$rule->silent) {
                         if ($this->root) {
                             $rulesets[] = $rule->toCSS($env);
                         } else {
                             $rules[] = $rule->toCSS($env);
                         }
                     }
                 } else {
                     if (Less_Parser::is_method($rule, 'toCSS') && (!isset($rule->variable) || !$rule->variable)) {
                         if ($this->firstRoot && $rule instanceof Less_Tree_Rule) {
                             throw new Less_CompilerError("properties must be inside selector blocks, they cannot be in the root.");
                         }
                         $rules[] = $rule->toCSS($env);
                     } else {
                         if (isset($rule->value) && $rule->value && !$rule->variable) {
                             $rules[] = (string) $rule->value;
                         }
                     }
                 }
             }
         }
     }
     $rulesets = implode('', $rulesets);
     // If this is the root node, we don't render
     // a selector, or {}.
     // Otherwise, only output if this ruleset has rules.
     if ($this->root) {
         if ($env->compress) {
             $css .= rtrim(implode('', $rules), ';');
         } else {
             $css .= implode("\n", $rules);
         }
     } else {
         if (count($rules)) {
             $selector = array();
             foreach ($this->paths as $p) {
                 $_p = '';
                 foreach ($p as $s) {
                     $_p .= $s->toCSS($env);
                 }
                 $selector[] = trim($_p);
             }
             $css .= implode($env->compress ? ',' : ",\n", $selector);
             // Remove duplicates
             for ($i = count($rules) - 1; $i >= 0; $i--) {
                 if (substr($rules[$i], 0, 2) === "/*" || !in_array($rules[$i], $_rules)) {
                     array_unshift($_rules, $rules[$i]);
                 }
             }
             $rules = $_rules;
             if ($env->compress) {
                 $css .= '{' . rtrim(implode('', $rules), ';') . '}';
             } else {
                 $css .= " {\n  " . implode("\n  ", $rules) . "\n}\n";
             }
         }
     }
     $css .= $rulesets;
     return $css . ($env->compress ? "\n" : '');
 }