Exemple #1
0
 /**
  * Parse this node.
  * If a CSS import returns the import rule.
  * Else returns the rendered tree for the file.
  * @param SassContext the context in which this node is parsed
  * @return array the parsed node
  */
 public function parse($context)
 {
     if (preg_match(self::MATCH_CSS, $this->uri)) {
         return "@import {$this->uri}";
     } else {
         $tree = SassFile::getTree(SassFile::getFile($this->uri, $this->options), $this->options);
         if (empty($tree)) {
             throw new SassImportNodeException("Unable to create document tree for {$this->uri}");
         } else {
             return $tree->parse($context)->children;
         }
     }
 }
Exemple #2
0
 /**
  * Parse this node.
  * If the node is a CSS import return the CSS import rule.
  * Else returns the rendered tree for the file.
  * 
  * @param
  *        	SassContext the context in which this node is parsed
  * @return array the parsed node
  */
 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;
 }
Exemple #3
0
 /**
  * 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.
  * @param string name of source file or Sass source
  * @return SassRootNode Root node of document tree
  */
 public function parse($source, $isFile = true)
 {
     if ($isFile) {
         $this->filename = SassFile::getFile($source, $this);
         if ($isFile) {
             $this->syntax = substr($this->filename, -4);
         } elseif ($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);
     }
 }
Exemple #4
0
 /**
  * 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.
  * @param string name of source file or Sass source
  * @return SassRootNode Root node of document tree
  */
 public function parse($source, $isFile = true)
 {
     if ($isFile) {
         $filename = SassFile::getFile($source, $this->options);
         $this->options['file']['dirname'] = dirname($filename);
         $this->options['file']['basename'] = basename($filename);
         if ($this->options['cache']) {
             $cached = SassFile::getCachedFile($filename, $this->options);
             if ($cached !== false) {
                 return $cached;
             }
         }
         $tree = $this->toTree(file($filename, FILE_IGNORE_NEW_LINES));
         if ($this->options['cache']) {
             SassFile::setCachedFile($tree, $filename, $this->options);
         }
         return $tree;
     } else {
         return $this->toTree(explode("\n", $source));
     }
 }