public function compile($env, $args = array()) { $frame = new \Less\Node\Ruleset(null, array()); foreach ($this->params as $i => $param) { if (isset($param['name']) && $param['name']) { if ($val = isset($args[$i]) ? $args[$i] : $param['value']) { $rule = new \Less\Node\Rule($param['name'], $val->compile($env)); array_unshift($frame->rules, $rule); } else { throw new \Less\Exception\CompilerException("wrong number of arguments for " . $this->name . ' (' . count($args) . ' for ' . $this->arity . ')'); } } } $_arguments = array(); for ($i = 0; $i < max(count($this->params), count($args)); $i++) { $_arguments[] = isset($args[$i]) ? $args[$i] : $this->params[$i]['value']; } $ex = new \Less\Node\Expression($_arguments); array_unshift($frame->rules, new \Less\Node\Rule('@arguments', $ex->compile($env))); // duplicate the environment, adding new frames. $ruleSetEnv = new \Less\Environment(); $ruleSetEnv->addFrame($this); $ruleSetEnv->addFrame($frame); $ruleSetEnv->addFrames($this->frames); $ruleSetEnv->addFrames($env->frames); $ruleset = new \Less\Node\Ruleset(null, $this->rules); return $ruleset->compile($ruleSetEnv); }
/** * Parse a Less string into css * * @param string $str The string to convert * @param bool $returnRoot Indicates whether the return value should be a css string a root node * @return \Less\Node\Ruleset|\Less\Parser */ public function parse($str, $returnRoot = false) { $this->pos = 0; $this->input = preg_replace('/\\r\\n/', "\n", $str); $root = new \Less\Node\Ruleset(false, $this->match('parsePrimary')); $root->root = true; if ($returnRoot) { return $root; } else { $this->css .= $root->compile($this->env)->toCSS(array(), $this->env); return $this; } }