You are here

public function SassParser::parse in Sassy 7

Same name and namespace in other branches
  1. 7.3 phpsass/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 SassRootNode Root node of document tree

File

phamlp/sass/SassParser.php, line 458

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) {
  if ($isFile) {
    $this->filename = SassFile::getFile($source, $this);
    $this->syntax = substr($this->filename, -4);
    if ($this->syntax !== SassFile::SASS && $this->syntax !== SassFile::SCSS) {
      throw new SassException('Invalid {what}', array(
        '{what}' => 'syntax option',
      ));
    }
    if ($this->cache) {
      $cached = SassFile::getCachedFile($this->filename, $this->cache_location);
      if ($cached !== false) {
        return $cached;
      }
    }
    $tree = $this
      ->toTree(file_get_contents($this->filename));
    if ($this->cache) {
      SassFile::setCachedFile($tree, $this->filename, $this->cache_location);
    }
    return $tree;
  }
  else {
    return $this
      ->toTree($source);
  }
}