public function Init() { self::$parensStack = 0; self::$tabLevel = 0; self::$lastRule = false; self::$mixin_stack = 0; if (Less_Parser::$options['compress']) { Less_Environment::$_outputMap = array(',' => ',', ': ' => ':', '' => '', ' ' => ' ', ':' => ' :', '+' => '+', '~' => '~', '>' => '>', '|' => '|', '^' => '^', '^^' => '^^'); } else { Less_Environment::$_outputMap = array(',' => ', ', ': ' => ': ', '' => '', ' ' => ' ', ':' => ' :', '+' => ' + ', '~' => ' ~ ', '>' => ' > ', '|' => '|', '^' => ' ^ ', '^^' => ' ^^ '); } }
/** * @see Less_Tree::genCSS */ public function genCSS($output) { if (!$this->root) { Less_Environment::$tabLevel++; } $tabRuleStr = $tabSetStr = ''; if (!Less_Parser::$options['compress']) { if (Less_Environment::$tabLevel) { $tabRuleStr = "\n" . str_repeat(' ', Less_Environment::$tabLevel); $tabSetStr = "\n" . str_repeat(' ', Less_Environment::$tabLevel - 1); } else { $tabSetStr = $tabRuleStr = "\n"; } } $ruleNodes = array(); $rulesetNodes = array(); foreach ($this->rules as $rule) { $class = get_class($rule); if ($class === 'Less_Tree_Media' || $class === 'Less_Tree_Directive' || $this->root && $class === 'Less_Tree_Comment' || $class === 'Less_Tree_Ruleset' && $rule->rules) { $rulesetNodes[] = $rule; } else { $ruleNodes[] = $rule; } } // If this is the root node, we don't render // a selector, or {}. if (!$this->root) { /* debugInfo = tree.debugInfo(env, this, tabSetStr); if (debugInfo) { output.add(debugInfo); output.add(tabSetStr); } */ $paths_len = count($this->paths); for ($i = 0; $i < $paths_len; $i++) { $path = $this->paths[$i]; $firstSelector = true; foreach ($path as $p) { $p->genCSS($output, $firstSelector); $firstSelector = false; } if ($i + 1 < $paths_len) { $output->add(',' . $tabSetStr); } } $output->add((Less_Parser::$options['compress'] ? '{' : " {") . $tabRuleStr); } // Compile rules and rulesets $ruleNodes_len = count($ruleNodes); $rulesetNodes_len = count($rulesetNodes); for ($i = 0; $i < $ruleNodes_len; $i++) { $rule = $ruleNodes[$i]; // @page{ directive ends up with root elements inside it, a mix of rules and rulesets // In this instance we do not know whether it is the last property if ($i + 1 === $ruleNodes_len && (!$this->root || $rulesetNodes_len === 0 || $this->firstRoot)) { Less_Environment::$lastRule = true; } $rule->genCSS($output); if (!Less_Environment::$lastRule) { $output->add($tabRuleStr); } else { Less_Environment::$lastRule = false; } } if (!$this->root) { $output->add($tabSetStr . '}'); Less_Environment::$tabLevel--; } $firstRuleset = true; $space = $this->root ? $tabRuleStr : $tabSetStr; for ($i = 0; $i < $rulesetNodes_len; $i++) { if ($ruleNodes_len && $firstRuleset) { $output->add($space); } elseif (!$firstRuleset) { $output->add($space); } $firstRuleset = false; $rulesetNodes[$i]->genCSS($output); } if (!Less_Parser::$options['compress'] && $this->firstRoot) { $output->add("\n"); } }
public function genCSS($output) { if (!$this->root) { Less_Environment::$tabLevel++; }$tabRuleStr = $tabSetStr = ''; if (!Less_Parser::$options['compress']) { if (Less_Environment::$tabLevel) { $tabRuleStr = "\n" . str_repeat(' ', Less_Environment::$tabLevel); $tabSetStr = "\n" . str_repeat(' ', Less_Environment::$tabLevel - 1); } else { $tabSetStr = $tabRuleStr = "\n"; } }$ruleNodes = array(); $rulesetNodes = array(); foreach ($this->rules as $rule) { $class = get_class($rule); if (($class === 'Less_Tree_Media') || ($class === 'Less_Tree_Directive') || ($this->root && $class === 'Less_Tree_Comment') || ($class === 'Less_Tree_Ruleset' && $rule->rules)) { $rulesetNodes[] = $rule; } else { $ruleNodes[] = $rule; } }if (!$this->root) { $paths_len = count($this->paths); for ($i = 0; $i < $paths_len; $i++) { $path = $this->paths[$i]; $firstSelector = true; foreach ($path as $p) { $p->genCSS($output, $firstSelector); $firstSelector = false; }if ($i + 1 < $paths_len) { $output->add(',' . $tabSetStr); } }$output->add((Less_Parser::$options['compress'] ? '{' : " {") . $tabRuleStr); }$ruleNodes_len = count($ruleNodes); $rulesetNodes_len = count($rulesetNodes); for ($i = 0; $i < $ruleNodes_len; $i++) { $rule = $ruleNodes[$i]; if ($i + 1 === $ruleNodes_len && (!$this->root || $rulesetNodes_len === 0 || $this->firstRoot)) { Less_Environment::$lastRule = true; }$rule->genCSS($output); if (!Less_Environment::$lastRule) { $output->add($tabRuleStr); } else { Less_Environment::$lastRule = false; } }if (!$this->root) { $output->add($tabSetStr . '}'); Less_Environment::$tabLevel--; }$firstRuleset = true; $space = ($this->root ? $tabRuleStr : $tabSetStr); for ($i = 0; $i < $rulesetNodes_len; $i++) { if ($ruleNodes_len && $firstRuleset) { $output->add($space); } elseif (!$firstRuleset) { $output->add($space); }$firstRuleset = false; $rulesetNodes[$i]->genCSS($output); }if (!Less_Parser::$options['compress'] && $this->firstRoot) { $output->add("\n"); } }