[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

/lib/lessphp/Tree/ -> Rule.php (source)

   1  <?php
   2  
   3  /**
   4   * Rule
   5   *
   6   * @package Less
   7   * @subpackage tree
   8   */
   9  class Less_Tree_Rule extends Less_Tree{
  10  
  11      public $name;
  12      public $value;
  13      public $important;
  14      public $merge;
  15      public $index;
  16      public $inline;
  17      public $variable;
  18      public $currentFileInfo;
  19      public $type = 'Rule';
  20  
  21      /**
  22       * @param string $important
  23       */
  24  	public function __construct($name, $value = null, $important = null, $merge = null, $index = null, $currentFileInfo = null,  $inline = false){
  25          $this->name = $name;
  26          $this->value = ($value instanceof Less_Tree_Value || $value instanceof Less_Tree_Ruleset) ? $value : new Less_Tree_Value(array($value));
  27          $this->important = $important ? ' ' . trim($important) : '';
  28          $this->merge = $merge;
  29          $this->index = $index;
  30          $this->currentFileInfo = $currentFileInfo;
  31          $this->inline = $inline;
  32          $this->variable = ( is_string($name) && $name[0] === '@');
  33      }
  34  
  35      public function accept($visitor) {
  36          $this->value = $visitor->visitObj( $this->value );
  37      }
  38  
  39      /**
  40       * @see Less_Tree::genCSS
  41       */
  42      public function genCSS( $output ){
  43  
  44          $output->add( $this->name . Less_Environment::$_outputMap[': '], $this->currentFileInfo, $this->index);
  45          try{
  46              $this->value->genCSS( $output);
  47  
  48          }catch( Less_Exception_Parser $e ){
  49              $e->index = $this->index;
  50              $e->currentFile = $this->currentFileInfo;
  51              throw $e;
  52          }
  53          $output->add( $this->important . (($this->inline || (Less_Environment::$lastRule && Less_Parser::$options['compress'])) ? "" : ";"), $this->currentFileInfo, $this->index);
  54      }
  55  
  56  	public function compile ($env){
  57  
  58          $name = $this->name;
  59          if( is_array($name) ){
  60              // expand 'primitive' name directly to get
  61              // things faster (~10% for benchmark.less):
  62              if( count($name) === 1 && $name[0] instanceof Less_Tree_Keyword ){
  63                  $name = $name[0]->value;
  64              }else{
  65                  $name = $this->CompileName($env,$name);
  66              }
  67          }
  68  
  69          $strictMathBypass = Less_Parser::$options['strictMath'];
  70          if( $name === "font" && !Less_Parser::$options['strictMath'] ){
  71              Less_Parser::$options['strictMath'] = true;
  72          }
  73  
  74          try {
  75              $evaldValue = $this->value->compile($env);
  76  
  77              if( !$this->variable && $evaldValue->type === "DetachedRuleset") {
  78                  throw new Less_Exception_Compiler("Rulesets cannot be evaluated on a property.", null, $this->index, $this->currentFileInfo);
  79              }
  80  
  81              if( Less_Environment::$mixin_stack ){
  82                  $return = new Less_Tree_Rule($name, $evaldValue, $this->important, $this->merge, $this->index, $this->currentFileInfo, $this->inline);
  83              }else{
  84                  $this->name = $name;
  85                  $this->value = $evaldValue;
  86                  $return = $this;
  87              }
  88  
  89          }catch( Less_Exception_Parser $e ){
  90              if( !is_numeric($e->index) ){
  91                  $e->index = $this->index;
  92                  $e->currentFile = $this->currentFileInfo;
  93              }
  94              throw $e;
  95          }
  96  
  97          Less_Parser::$options['strictMath'] = $strictMathBypass;
  98  
  99          return $return;
 100      }
 101  
 102  
 103      public function CompileName( $env, $name ){
 104          $output = new Less_Output();
 105          foreach($name as $n){
 106              $n->compile($env)->genCSS($output);
 107          }
 108          return $output->toString();
 109      }
 110  
 111      public function makeImportant(){
 112          return new Less_Tree_Rule($this->name, $this->value, '!important', $this->merge, $this->index, $this->currentFileInfo, $this->inline);
 113      }
 114  
 115  }


Generated: Thu Aug 11 10:00:09 2016 Cross-referenced by PHPXref 0.7.1