SassVariableNode.php in Sassy 7.3
File
phpsass/tree/SassVariableNode.php
View source
<?php
class SassVariableNode extends SassNode {
const MATCH = '/^([!$])([\\w-]+)\\s*:?\\s*((\\|\\|)?=)?\\s*(.+?)\\s*(!default)?;?$/i';
const IDENTIFIER = 1;
const NAME = 2;
const SASS_ASSIGNMENT = 3;
const SASS_DEFAULT = 4;
const VALUE = 5;
const SCSS_DEFAULT = 6;
const SASS_IDENTIFIER = '!';
const SCSS_IDENTIFIER = '$';
private $name;
private $value;
private $isDefault;
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]);
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' : ''));
}
}
public function parse($context) {
if (!$this->isDefault || !$context
->hasVariable($this->name)) {
$context
->setVariable($this->name, $this
->evaluate($this->value, $context));
}
$this
->parseChildren($context);
return array();
}
public static function isa($token) {
return $token->source[0] === self::SASS_IDENTIFIER || $token->source[0] === self::SCSS_IDENTIFIER;
}
}
Classes
Name |
Description |
SassVariableNode |
SassVariableNode class.
Represents a variable.
@package PHamlP
@subpackage Sass.tree |