Example #1
0
 /**
  * @param object $token source token
  * @param Node $parent
  */
 public function __construct($token, $parent)
 {
     parent::__construct($token);
     $this->parent = $parent;
     preg_match(self::MATCH, $token->source, $matches);
     foreach (\PHPSass\Script\Literals\SassList::_build_list($matches[self::FILES]) as $file) {
         $this->files[] = trim($file, '"\'; ');
     }
 }
Example #2
0
 /**
  * Parse this node.
  *
  * @param Context $context the context in which this node is parsed
  * @return array parsed child nodes
  */
 public function parse($context)
 {
     $children = [];
     if ($this->variable && $this->in) {
         $context = new Context($context);
         list($in, $sep) = \PHPSass\Script\Literals\SassList::_parse_list($this->in, 'auto', TRUE, $context);
         foreach ($in as $var) {
             $context->setVariable($this->variable, $var);
             $children = array_merge($children, $this->parseChildren($context));
         }
     }
     $context->merge();
     return $children;
 }
Example #3
0
 /**
  * Resolves selectors.
  * Interpolates Script in selectors and resolves any parent references or
  * appends the parent selectors.
  *
  * @param Context $context the context in which this node is parsed
  * @return array
  *
  * Change: 7/Dec/11 - change to make selector ordering conform to Ruby compiler.
  */
 public function resolveSelectors($context)
 {
     $resolvedSelectors = $normalSelectors = [];
     $this->parentSelectors = $this->getParentSelectors($context);
     foreach ($this->selectors as $selector) {
         $selector = $this->interpolate($selector, $context);
         $selectors = \PHPSass\Script\Literals\SassList::_build_list($selector);
         foreach ($selectors as $selector_inner) {
             $selector_inner = trim($selector_inner, ' \'"');
             // strip whitespace and quotes, just-in-case.
             if ($this->hasParentReference($selector_inner)) {
                 $resolvedSelectors = array_merge($resolvedSelectors, $this->resolveParentReferences($selector_inner, $context));
             } else {
                 $normalSelectors[] = $selector_inner;
             }
         }
     }
     // merge with parent selectors
     if ($this->parentSelectors) {
         $return = [];
         foreach ($this->parentSelectors as $parent) {
             foreach ($normalSelectors as $selector) {
                 $spacer = substr($selector, 0, 1) == '[' ? '' : ' ';
                 $return[] = $parent . $spacer . $selector;
             }
         }
         $normalSelectors = $return;
     }
     return array_merge($normalSelectors, $resolvedSelectors);
 }
Example #4
0
 /**
  * @param string $string
  * @param bool $include_null
  * @param Context $context
  * @return array
  */
 public static function extractArgs($string, $include_null = TRUE, $context)
 {
     $list = Literals\SassList::_build_list($string, ',');
     $return = [];
     foreach ($list as $k => $value) {
         if (substr($value, -3, 3) == '...' && preg_match(Tree\VariableNode::MATCH, substr($value, 0, -3) . ':', $match)) {
             $list = new Literals\SassList($context->getVariable($match[Tree\VariableNode::NAME]));
             if (count($list->value) > 1) {
                 $return = array_merge($return, $list->value);
                 continue;
             }
         }
         if (strpos($value, ':') !== FALSE && preg_match(Tree\VariableNode::MATCH, $value, $match)) {
             $return[$match[Tree\VariableNode::NAME]] = $match[Tree\VariableNode::VALUE];
         } elseif (substr($value, 0, 1) == '$' && $include_null) {
             $return[str_replace('$', '', $value)] = NULL;
         } elseif ($include_null || $value !== NULL) {
             $return[] = $value;
         }
     }
     return $return;
 }