Defines the context that the parser is operating in and so allows variables to be scoped. A new context is created for Mixins and imported files.
Exemplo n.º 1
0
 /**
  * Parse this node.
  * Set passed arguments and any optional arguments not passed to their
  * defaults, then render the children of the mixin definition.
  * @param SassContext the context in which this node is parsed
  * @return array the parsed node
  */
 public function parse($pcontext)
 {
     $mixin = $pcontext->getMixin($this->name);
     $context = new SassContext($pcontext);
     $argc = count($this->args);
     $count = 0;
     foreach ($mixin->args as $name => $value) {
         if ($count < $argc) {
             $context->setVariable($name, $this->evaluate($this->args[$count++], $context));
         } elseif (!is_null($value)) {
             $context->setVariable($name, $this->evaluate($value, $context));
         } else {
             throw new SassMixinNodeException("Mixin::{mname}: Required variable ({vname}) not given.\nMixin defined: {dfile}::{dline}\nMixin used", array('{vname}' => $name, '{mname}' => $this->name, '{dfile}' => $mixin->token->filename, '{dline}' => $mixin->token->line), $this);
         }
     }
     // foreach
     $children = array();
     foreach ($mixin->children as $child) {
         $child->parent = $this;
         $children = array_merge($children, $child->parse($context));
     }
     // foreach
     //$context->merge();
     return $children;
 }
Exemplo n.º 2
0
 /**
  * Parse this node.
  * Sets the variable in the current context.
  * @param SassContext $context the context in which this node is parsed
  * @return array the parsed node - an empty array
  */
 public function parse($context)
 {
     if (!$this->isDefault || !$context->hasVariable($this->name)) {
         $context->setVariable($this->name, $this->evaluate($this->value, $context));
     }
     $this->parseChildren($context);
     // Parse any warnings
     return array();
 }
Exemplo n.º 3
0
 /**
  * Parse this node.
  * Set passed arguments and any optional arguments not passed to their
  * defaults, then render the children of the return definition.
  * @param SassContext the context in which this node is parsed
  * @return array the parsed node
  */
 public function parse($pcontext)
 {
     $return = $this;
     $context = new SassContext($pcontext);
     $children = array();
     foreach ($context->getContent() as $child) {
         $child->parent = $this->parent;
         $children = array_merge($children, $child->parse($pcontext));
     }
     return $children;
 }
Exemplo n.º 4
0
 /**
  * Parse this node.
  * Set passed arguments and any optional arguments not passed to their
  * defaults, then render the children of the mixin definition.
  * @param SassContext $pcontext the context in which this node is parsed
  * @return array the parsed node
  */
 public function parse($pcontext)
 {
     $mixin = $pcontext->getMixin($this->name);
     $context = new SassContext($pcontext);
     $context->content = $this->children;
     $argc = count($this->args);
     $count = 0;
     $args = SassScriptFunction::extractArgs($this->args, false, $context);
     list($arguments) = SassScriptFunction::fill_parameters($mixin->args, $args, $context, $this);
     $context->setVariables($arguments);
     $children = array();
     foreach ($mixin->children as $child) {
         /** @var $child SassNode */
         $child->parent = $this;
         $children = array_merge($children, $child->parse($context));
     }
     // $context->merge();
     return $children;
 }
Exemplo n.º 5
0
 /**
  * Parse this node.
  * Set any attributes passed and any optional arguments not passed to their
  * defaults, then render the children of the mixin definition.
  * @param SassContext the context in which this node is parsed
  * @return array the parsed node
  */
 public function parse($context)
 {
     $mixin = $context->getMixin($this->name);
     $context = new SassContext($context);
     foreach ($mixin->args as $n => $name) {
         if (isset($this->args[$n])) {
             $context->setVariable($name, $this->evaluate($this->args[$n], $context));
         } elseif ($mixin->hasDefault($name)) {
             $context->setVariable($name, $this->evaluate($mixin->getDefault($name), $context));
         } else {
             throw new SassMixinNodeException("Required variable - {$name} - not given when using Mixin::{$this->name}\nMixin used at Line {$this->line['number']}: " . (is_array($this->line['file']) ? join(DIRECTORY_SEPARATOR, $this->line['file']) : '') . "\nMixin defined at Line {$mixin->line['number']}: " . (is_array($mixin->line['file']) ? join(DIRECTORY_SEPARATOR, $mixin->line['file']) : ''));
         }
     }
     // foreach
     $children = array();
     foreach ($mixin->children as $child) {
         $child->parent = $this;
         $children = array_merge($children, $child->parse($context));
     }
     // foreach
     $context->merge();
     return $children;
 }
Exemplo n.º 6
0
 /**
  * Parse this node.
  * @param SassContext the context in which this node is parsed
  * @return array parsed child nodes
  */
 public function parse($context)
 {
     $children = array();
     $from = $this->evaluate($this->from, $context);
     $to = $this->evaluate($this->to, $context);
     $step = $this->evaluate($this->step, $context) * ($to > $from ? 1 : -1);
     if ($this->inclusive) {
         $to += $from < $to ? 1 : -1;
     }
     $context = new SassContext($context);
     for ($i = $from; $from < $to ? $i < $to : $i > $to; $i = $i + $step) {
         $context->setVariable($this->variable, $i);
         foreach ($this->children as $child) {
             $children = array_merge($children, $child->parse($context));
         }
         // foreach
     }
     return $children;
 }
Exemplo n.º 7
0
 /**
  * Parse this node.
  * 
  * @param
  *        	SassContext the context in which this node is parsed
  * @return array parsed child nodes
  */
 public function parse($context)
 {
     $children = array();
     $from = (double) $this->evaluate($this->from, $context)->value;
     $to = (double) $this->evaluate($this->to, $context)->value;
     $step = (double) $this->evaluate($this->step, $context)->value * ($to > $from ? 1 : -1);
     if ($this->inclusive) {
         $to += $from < $to ? 1 : -1;
     }
     $context = new SassContext($context);
     for ($i = $from; $from < $to ? $i < $to : $i > $to; $i = $i + $step) {
         $context->setVariable($this->variable, new SassNumber($i));
         $children = array_merge($children, $this->parseChildren($context));
     }
     return $children;
 }
 /**
  * Parse this node.
  * Set passed arguments and any optional arguments not passed to their
  * defaults, then render the children of the return definition.
  * @param SassContext the context in which this node is parsed
  * @return array the parsed node
  */
 public function parse($pcontext)
 {
     $return = $this;
     $context = new SassContext($pcontext);
     return $context->getContent();
 }
Exemplo n.º 9
0
 /**
  * Returns the SassScript object for this variable.
  * @param SassContext $context context of the variable
  * @return SassLiteral the SassScript object for this variable
  */
 public function evaluate($context)
 {
     return $context->getVariable($this->name);
 }
Exemplo n.º 10
0
 /**
  * Parse this node.
  * Add this mixin to  the current context.
  * @param SassContext $context the context in which this node is parsed
  * @return array the parsed node - an empty array
  */
 public function parse($context)
 {
     $context->addMixin($this->name, $this);
     return array();
 }