9 class Less_Tree_Rule
extends Less_Tree
{
18 public $currentFileInfo;
19 public $type = 'Rule';
22 * @param string $important
24 public function __construct($name, $value = null, $important = null, $merge = null, $index = null, $currentFileInfo = null, $inline = false){
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] === '@');
35 function accept($visitor) {
36 $this->value
= $visitor->visitObj( $this->value
);
40 * @see Less_Tree::genCSS
42 function genCSS( $output ){
44 $output->add( $this->name
. Less_Environment
::$_outputMap[': '], $this->currentFileInfo
, $this->index
);
46 $this->value
->genCSS( $output);
48 }catch( Less_Exception_Parser
$e ){
49 $e->index
= $this->index
;
50 $e->currentFile
= $this->currentFileInfo
;
53 $output->add( $this->important
. (($this->inline ||
(Less_Environment
::$lastRule && Less_Parser
::$options['compress'])) ?
"" : ";"), $this->currentFileInfo
, $this->index
);
56 public function compile ($env){
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
;
65 $name = $this->CompileName($env,$name);
69 $strictMathBypass = Less_Parser
::$options['strictMath'];
70 if( $name === "font" && !Less_Parser
::$options['strictMath'] ){
71 Less_Parser
::$options['strictMath'] = true;
75 $evaldValue = $this->value
->compile($env);
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
);
81 if( Less_Environment
::$mixin_stack ){
82 $return = new Less_Tree_Rule($name, $evaldValue, $this->important
, $this->merge
, $this->index
, $this->currentFileInfo
, $this->inline
);
85 $this->value
= $evaldValue;
89 }catch( Less_Exception_Parser
$e ){
90 if( !is_numeric($e->index
) ){
91 $e->index
= $this->index
;
92 $e->currentFile
= $this->currentFileInfo
;
97 Less_Parser
::$options['strictMath'] = $strictMathBypass;
103 function CompileName( $env, $name ){
104 $output = new Less_Output();
105 foreach($name as $n){
106 $n->compile($env)->genCSS($output);
108 return $output->toString();
111 function makeImportant(){
112 return new Less_Tree_Rule($this->name
, $this->value
, '!important', $this->merge
, $this->index
, $this->currentFileInfo
, $this->inline
);