SassImportNode.php in Sassy 7
File
phamlp/sass/tree/SassImportNode.php
View source
<?php
class SassImportNode extends SassNode {
const IDENTIFIER = '@';
const MATCH = '/^@import\\s+(.+)/i';
const MATCH_CSS = '/^(.+\\.css|url\\(.+\\)|.+" \\w+|"http)/im';
const FILES = 1;
private $files = array();
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);
}
}
public function parse($context) {
$imported = array();
foreach ($this->files as $file) {
if (preg_match(self::MATCH_CSS, $file)) {
return "@import {$file}";
}
else {
$file = trim($file, '\'"');
$tree = SassFile::getTree(SassFile::getFile($file, $this->parser), $this->parser);
if (empty($tree)) {
throw new SassImportNodeException('Unable to create document tree for {file}', array(
'{file}' => $file,
), $this);
}
else {
$imported = array_merge($imported, $tree
->parse($context)->children);
}
}
}
return $imported;
}
}
Classes
Name |
Description |
SassImportNode |
SassImportNode class.
Represents a CSS Import.
@package PHamlP
@subpackage Sass.tree |