public function SassParser::parse in Sassy 7.3
Same name and namespace in other branches
- 7 phamlp/sass/SassParser.php \SassParser::parse()
Parse a sass file or Sass source code and returns the document tree that can then be rendered. The file will be searched for in the directories specified by the load_paths option. If caching is enabled a cached version will be used if possible or the compiled version cached if not.
Parameters
string name of source file or Sass source:
Return value
SassRootNode Root node of document tree
File
- phpsass/
SassParser.php, line 496
Class
- SassParser
- SassParser class. Parses {@link http://sass-lang.com/ .sass and .sccs} files. @package PHamlP @subpackage Sass
Code
public function parse($source, $isFile = true) {
# Richard Lyon - 2011-10-25 - ignore unfound files
# Richard Lyon - 2011-10-25 - add multiple files to load functions
if (!$source) {
return $this
->toTree($source);
}
if (is_array($source)) {
$return = array();
foreach ($source as $source_file) {
$return = array_merge($return, $this
->parse($source_file, TRUE));
}
return $return;
}
if ($isFile && ($files = SassFile::get_file($source, $this))) {
$files_source = '';
foreach ($files as $file) {
$this->filename = $file;
$this->syntax = substr($this->filename, -4);
if ($this->syntax !== SassFile::SASS && $this->syntax !== SassFile::SCSS) {
if ($this->debug) {
throw new SassException('Invalid {what}', array(
'{what}' => 'syntax option',
));
}
return FALSE;
}
if ($this->cache) {
$cached = SassFile::get_cached_file($this->filename, $this->cache_location);
if ($cached !== false) {
return $cached;
}
}
$contents = file_get_contents($this->filename);
SassFile::$parser = $this;
SassFile::$path = $this->filename;
$contents = preg_replace_callback('/url\\(\\s*[\'"]?(?![a-z]+:|\\/+)([^\'")]+)[\'"]?\\s*\\)/i', 'SassFile::resolve_paths', $contents);
$files_source .= $contents;
if ($this->cache) {
SassFile::set_cached_file($tree, $filename, $this->cache_location);
}
}
return $this
->toTree($files_source);
}
else {
return $this
->toTree($source);
}
}