SassMixinDefinitionNode.php in Sassy 7
File
phamlp/sass/tree/SassMixinDefinitionNode.php
View source
<?php
class SassMixinDefinitionNode extends SassNode {
const NODE_IDENTIFIER = '=';
const MATCH = '/^(=|@mixin\\s+)([-\\w]+)\\s*(?:\\((.+?)\\))?\\s*$/i';
const IDENTIFIER = 1;
const NAME = 2;
const ARGUMENTS = 3;
private $name;
private $args = array();
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;
}
}
}
public function parse($context) {
$context
->addMixin($this->name, $this);
return array();
}
public function getArgs() {
return $this->args;
}
public static function isa($token) {
return $token->source[0] === self::NODE_IDENTIFIER;
}
}
Classes
Name |
Description |
SassMixinDefinitionNode |
SassMixinDefinitionNode class.
Represents a Mixin definition.
@package PHamlP
@subpackage Sass.tree |