setVariable() public method

Sets a variable to the given value
public setVariable ( string $name, sassLiteral $value ) : SassContext
$name string name of variable
$value sassLiteral value of variable
return SassContext
Example #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;
 }
Example #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();
 }
Example #3
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;
 }
Example #4
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;
 }
Example #5
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;
 }