SassImportNode.php in Sassy 7.3
File
phpsass/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, '\'"');
$files = SassFile::get_file($file, $this->parser, TRUE);
$tree = array();
if ($files) {
$tree = SassFile::get_tree(array_shift($files), $this->parser);
foreach ($files as $file) {
$file = SassFile::get_tree($file, $this->parser);
foreach ($file
->getChildren() as $child) {
$tree
->addChild($child);
}
}
}
if (!empty($tree)) {
$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 |