You are here

public function SassMixinNode::parse in Sassy 7

Same name and namespace in other branches
  1. 7.3 phpsass/tree/SassMixinNode.php \SassMixinNode::parse()

* Parse this node. * Set passed arguments and any optional arguments not passed to their * defaults, then render the children of the mixin definition. *

Parameters

SassContext the context in which this node is parsed: * @return array the parsed node

File

phamlp/sass/tree/SassMixinNode.php, line 55

Class

SassMixinNode
SassMixinNode class. Represents a Mixin. @package PHamlP @subpackage Sass.tree

Code

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;
}