Base class for all Sass nodes.
 /**
  * Renders rule selectors.
  * @param SassNode $node the node being rendered
  * @return string the rendered selectors
  */
 protected function renderSelectors($node)
 {
     $selectors = array();
     foreach ($node->selectors as $selector) {
         if (!$node->isPlaceholder($selector)) {
             $selectors[] = $selector;
         }
     }
     $indent = $this->getIndent($node);
     return $indent . join(",\n{$indent}", $selectors);
 }
Beispiel #2
0
 /**
  * SassWhileNode constructor.
  * @param object source token
  * @return SassWhileNode
  */
 public function __construct($token)
 {
     parent::__construct($token);
     preg_match(self::MATCH, $token->source, $matches);
     $this->expression = $matches[self::EXPRESSION];
     $this->isDo = $matches[self::LOOP] === SassWhileNode::IS_DO;
 }
Beispiel #3
0
 /**
  * SassMediaNode.
  * @param object source token
  * @param mixed string: an internally generated warning message about the
  * source
  * boolean: the source token is a @Media or @warn directive containing the
  * message; True if this is a @warn directive
  * @param array parameters for the message
  * @return SassMediaNode
  */
 public function __construct($token)
 {
     parent::__construct($token);
     preg_match(self::MATCH, $token->source, $matches);
     $this->token = $token;
     $this->media = $matches[self::MEDIA];
 }
 /**
  * SassContentNode constructor.
  * @param object source token
  * @return SassContentNode
  */
 public function __construct($token)
 {
     parent::__construct($token);
     preg_match(self::MATCH, $token->source, $matches);
     if (empty($matches)) {
         return new SassBoolean('false');
     }
 }
Beispiel #5
0
 /**
  * Root SassNode constructor.
  * @param SassParser Sass parser
  * @return SassNode
  */
 public function __construct($parser)
 {
     parent::__construct((object) array('source' => '', 'level' => -1, 'filename' => $parser->filename, 'line' => 0));
     $this->parser = $parser;
     $this->script = new SassScriptParser();
     $this->renderer = SassRenderer::getRenderer($parser->style);
     $this->root = $this;
 }
Beispiel #6
0
 /**
  * SassImportNode.
  * 
  * @param
  *        	object source token
  * @return SassImportNode
  */
 public function __construct($token)
 {
     parent::__construct($token);
     preg_match(self::MATCH, $token->source, $matches);
     foreach (explode(',', $matches[self::FILES]) as $file) {
         $this->files[] = trim($file);
     }
 }
Beispiel #7
0
 /**
  * SassImportNode.
  * @param object $token source token
  * @return SassImportNode
  */
 public function __construct($token, $parent)
 {
     parent::__construct($token);
     $this->parent = $parent;
     preg_match(self::MATCH, $token->source, $matches);
     foreach (SassList::_build_list($matches[self::FILES]) as $file) {
         $this->files[] = trim($file, '"\'; ');
     }
 }
Beispiel #8
0
 /**
  * SassReturnNode constructor.
  * @param object $token source token
  * @return SassReturnNode
  */
 public function __construct($token)
 {
     parent::__construct($token);
     preg_match(self::MATCH, $token->source, $matches);
     if (empty($matches)) {
         return new SassBoolean('false');
     }
     $this->statement = $matches[self::STATEMENT];
 }
Beispiel #9
0
 /**
  * SassMixinDefinitionNode constructor.
  * @param object source token
  * @return SassMixinNode
  */
 public function __construct($token)
 {
     parent::__construct($token);
     preg_match(self::MATCH, $token->source, $matches);
     $this->name = $matches[self::NAME];
     if (isset($matches[self::ARGS])) {
         $this->args = SassScriptFunction::extractArgs($matches[self::ARGS]);
     }
 }
Beispiel #10
0
 /**
  * SassPropertyNode constructor.
  * @param object source token
  * @param string property syntax
  * @return SassPropertyNode
  */
 public function __construct($token, $syntax = 'new')
 {
     parent::__construct($token);
     $matches = self::match($token, $syntax);
     $this->name = $matches[self::NAME];
     $this->value = $matches[self::VALUE];
     if ($matches[self::SCRIPT] === self::IS_SCRIPT) {
         $this->addWarning('Setting CSS properties with "=" is deprecated; use "{name}: {value};"', array('{name}' => $this->name, '{value}' => $this->value));
     }
 }
 /**
  * SassEachNode constructor.
  * @param object source token
  * @return SassEachNode
  */
 public function __construct($token)
 {
     parent::__construct($token);
     if (!preg_match(self::MATCH, $token->source, $matches)) {
         throw new SassEachNodeException('Invalid @each directive', $this);
     } else {
         $this->variable = trim($matches[self::VARIABLE]);
         $this->in = $matches[self::IN];
     }
 }
Beispiel #12
0
 /**
  * SassIfNode constructor.
  * @param object source token
  * @param boolean true for an "if" node, false for an "else if | else" node
  * @return SassIfNode
  */
 public function __construct($token, $if = true)
 {
     parent::__construct($token);
     if ($if) {
         preg_match(self::MATCH_IF, $token->source, $matches);
         $this->expression = $matches[SassIfNode::IF_EXPRESSION];
     } else {
         preg_match(self::MATCH_ELSE, $token->source, $matches);
         $this->expression = sizeof($matches) == 1 ? null : $matches[SassIfNode::ELSE_EXPRESSION];
     }
 }
 /**
  * SassMixinDefinitionNode constructor.
  * @param object source token
  * @return SassMixinNode
  */
 public function __construct($token)
 {
     parent::__construct($token);
     preg_match(self::MATCH, $token->source, $matches);
     if (!isset($matches[self::NAME])) {
         throw new SassMixinNodeException('Invalid mixin invocation: ($token->source)', $this);
     }
     $this->name = $matches[self::NAME];
     if (isset($matches[self::ARGS]) && strlen($matches[self::ARGS])) {
         $this->args = $matches[self::ARGS];
     }
 }
 /**
  * SassMixinDefinitionNode constructor.
  * @param object source token
  * @return SassMixinDefinitionNode
  */
 public function __construct($token)
 {
     preg_match(self::MATCH, $token->source, $matches);
     parent::__construct($token);
     if (empty($matches)) {
         throw new SassMixinDefinitionNodeException('Invalid Mixin', $this);
     }
     $this->name = $matches[self::NAME];
     if (isset($matches[self::ARGUMENTS])) {
         $this->args = SassScriptFunction::extractArgs($matches[self::ARGUMENTS], true, new SassContext());
     }
 }
Beispiel #15
0
 /**
  * SassDebugNode.
  * @param object source token
  * @param mixed string: an internally generated warning message about the
  * source
  * boolean: the source token is a @debug or @warn directive containing the
  * message; True if this is a @warn directive
  * @param array parameters for the message
  * @return SassDebugNode
  */
 public function __construct($token, $message = false)
 {
     parent::__construct($token);
     if (is_string($message)) {
         $this->message = $message;
         $this->warning = true;
     } else {
         preg_match(self::MATCH, $token->source, $matches);
         $this->message = $matches[self::MESSAGE];
         $this->warning = $message;
     }
 }
Beispiel #16
0
 /**
  * SassForNode constructor.
  * 
  * @param
  *        	object source token
  * @return SassForNode
  */
 public function __construct($token)
 {
     parent::__construct($token);
     if (!preg_match(self::MATCH, $token->source, $matches)) {
         throw new SassForNodeException('Invalid {what}', array('{what}' => '@for directive'), $this);
     }
     $this->variable = $matches[self::VARIABLE];
     $this->from = $matches[self::FROM];
     $this->to = $matches[self::TO];
     $this->inclusive = $matches[self::INCLUSIVE] === SassForNode::IS_INCLUSIVE;
     $this->step = empty($matches[self::STEP]) ? 1 : $matches[self::STEP];
 }
 /**
  * SassPropertyNode constructor.
  * @param object source token
  * @param string property syntax
  * @return SassPropertyNode
  */
 public function __construct($token, $syntax = 'new')
 {
     parent::__construct($token);
     $matches = self::match($token, $syntax);
     $this->name = @$matches[self::NAME];
     if (!isset($matches[self::VALUE])) {
         $this->value = '';
     } else {
         $this->value = $matches[self::VALUE];
         if ($matches[self::SCRIPT] === self::IS_SCRIPT) {
             $this->addWarning('Setting CSS properties with "=" is deprecated; use "{name}: {value};"', array('{name}' => $this->name, '{value}' => $this->value));
         }
     }
     $this->important = trim(array_pop($matches)) == '!important';
 }
 /**
  * SassMixinDefinitionNode constructor.
  * @param object source token
  * @return SassMixinDefinitionNode
  */
 public function __construct($token)
 {
     // if ($token->level > 1) {
     //   throw new SassMixinDefinitionNodeException('Mixins can only be defined at root level. Token was set at level ' . $token->level, $token);
     // }
     preg_match(self::MATCH, $token->source, $matches);
     parent::__construct($token);
     if (empty($matches)) {
         throw new SassMixinDefinitionNodeException('Invalid Mixin', $this);
     }
     $this->name = $matches[self::NAME];
     if (isset($matches[self::ARGUMENTS])) {
         $this->args = SassScriptFunction::extractArgs($matches[self::ARGUMENTS]);
     }
 }
Beispiel #19
0
 /**
  * SassVariableNode constructor.
  * @param object source token
  * @return SassVariableNode
  */
 public function __construct($token)
 {
     parent::__construct($token);
     preg_match(self::MATCH, $token->source, $matches);
     if (empty($matches[self::NAME]) || $matches[self::VALUE] === '') {
         throw new SassVariableNodeException('Invalid variable definition; name and expression required', $this);
     }
     $this->name = $matches[self::NAME];
     $this->value = $matches[self::VALUE];
     $this->isDefault = !empty($matches[self::SASS_DEFAULT]) || !empty($matches[self::SCSS_DEFAULT]);
     // Warn about deprecated features
     if ($matches[self::IDENTIFIER] === self::SASS_IDENTIFIER) {
         $this->addWarning('Variables prefixed with "!" is deprecated; use "' . $this->name . '"');
     }
     if (!empty($matches[SassVariableNode::SASS_ASSIGNMENT])) {
         $this->addWarning('Setting variables with "' . (!empty($matches[SassVariableNode::SASS_DEFAULT]) ? '||' : '') . '=" is deprecated; use "$' . $this->name . ': ' . $this->value . (!empty($matches[SassVariableNode::SASS_DEFAULT]) ? ' !default' : ''));
     }
 }
 /**
  * SassMixinDefinitionNode constructor.
  * @param object source token
  * @return SassMixinDefinitionNode
  */
 public function __construct($token)
 {
     if ($token->level !== 0) {
         throw new SassMixinDefinitionNodeException('Mixins can only be defined at root level', array(), $this);
     }
     parent::__construct($token);
     preg_match(self::MATCH, $token->source, $matches);
     if (empty($matches)) {
         throw new SassMixinDefinitionNodeException('Invalid {what}', array('{what}' => 'Mixin'), $this);
     }
     $this->name = $matches[self::NAME];
     if (isset($matches[self::ARGUMENTS])) {
         foreach (explode(',', $matches[self::ARGUMENTS]) as $arg) {
             $arg = explode($matches[self::IDENTIFIER] === self::NODE_IDENTIFIER ? '=' : ':', trim($arg));
             $this->args[substr(trim($arg[0]), 1)] = count($arg) == 2 ? trim($arg[1]) : null;
         }
         // foreach
     }
 }
 /**
  * SassFunctionDefinitionNode constructor.
  * @param object source token
  * @return SassFunctionDefinitionNode
  */
 public function __construct($token)
 {
     // if ($token->level !== 0) {
     //   throw new SassFunctionDefinitionNodeException('Functions can only be defined at root level', $token);
     // }
     parent::__construct($token);
     preg_match(self::MATCH, $token->source, $matches);
     if (empty($matches)) {
         throw new SassFunctionDefinitionNodeException('Invalid Function', $token);
     }
     $this->name = $matches[self::NAME];
     $this->name = preg_replace('/[^a-z0-9_]/', '_', strtolower($this->name));
     if (isset($matches[self::ARGUMENTS])) {
         if (strlen(trim($matches[self::ARGUMENTS]))) {
             foreach (explode(',', $matches[self::ARGUMENTS]) as $arg) {
                 $arg = explode($matches[self::IDENTIFIER] === self::NODE_IDENTIFIER ? '=' : ':', trim($arg));
                 $this->args[substr(trim($arg[0]), 1)] = count($arg) == 2 ? trim($arg[1]) : null;
             }
             // foreach
         }
     }
 }
 /**
  * @see parse
  */
 public function __clone()
 {
     parent::__clone();
     $this->token = clone $this->token;
 }
 /**
  * Renders rule selectors.
  * @param SassNode $node the node being rendered
  * @return string the rendered selectors
  */
 protected function renderSelectors($node)
 {
     $selectors = array();
     foreach ($node->selectors as $selector) {
         if (!$node->isPlaceholder($selector)) {
             $selectors[] = $selector;
         }
     }
     return join(', ', $selectors);
 }
Beispiel #24
0
 /**
  * Returns a value indicating if this node is a child of the passed node.
  * This just checks the levels of the nodes. If this node is at a greater
  * level than the passed node if is a child of it.
  *
  * @param SassNode $node
  *
  * @return boolean true if the node is a child of the passed node, false if not
  */
 public function isChildOf($node)
 {
     return $this->getLevel() > $node->getLevel();
 }
 /**
  * SassExtendNode.
  * @param object source token
  * @return SassExtendNode
  */
 public function __construct($token)
 {
     parent::__construct($token);
     preg_match(self::MATCH, $token->source, $matches);
     $this->value = $matches[self::VALUE];
 }
Beispiel #26
0
 /**
  * SassDirectiveNode.
  * @param object source token
  * @return SassDirectiveNode
  */
 public function __construct($token)
 {
     parent::__construct($token);
 }
Beispiel #27
0
 /**
  * SassRuleNode constructor.
  * @param object source token
  * @param string rule selector
  * @return SassRuleNode
  */
 public function __construct($token)
 {
     parent::__construct($token);
     preg_match(self::MATCH, $token->source, $matches);
     $this->addSelectors($matches[SassRuleNode::SELECTOR]);
 }