get_file() 공개 정적인 메소드

The file is looked for recursively under the load_paths directories If the filename does not end in .sass or .scss try the current syntax first then, if a file is not found, try the other syntax.
public static get_file ( string $filename, SassParser &$parser, boolean $sass_only = TRUE ) : array
$filename string filename to find
$parser SassParser Sass parser
$sass_only boolean
리턴 array of string path(s) to file(s) or FALSE if no such file
예제 #1
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 $context 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, $matches)) {
             if (isset($matches[2]) && $matches[2] == 'url') {
                 $file = $matches[1];
             } else {
                 $file = "url('{$file}')";
             }
             return array(new SassString("@import {$file};"), new SassString("\n"));
         }
         $file = trim($file, '\'"');
         $files = SassFile::get_file($file, $this->parser);
         $tree = array();
         if ($files) {
             if ($this->token->level > 0) {
                 $tree = $this->parent;
                 while (get_class($tree) != 'SassRuleNode' && get_class($tree) != 'SassRootNode' && isset($tree->parent)) {
                     $tree = $tree->parent;
                 }
                 $tree = clone $tree;
                 $tree->children = array();
             } else {
                 $tree = new SassRootNode($this->parser);
                 $tree->extend_parent = $this->parent;
             }
             foreach ($files as $subfile) {
                 if (preg_match(self::MATCH_CSS, $subfile)) {
                     $tree->addChild(new SassString("@import url('{$subfile}');"));
                 } else {
                     $this->parser->filename = $subfile;
                     $subtree = SassFile::get_tree($subfile, $this->parser);
                     foreach ($subtree->getChildren() as $child) {
                         $tree->addChild($child);
                     }
                 }
             }
         }
         if (!empty($tree)) {
             # parent may be either SassRootNode (returns an object) or SassRuleNode (returns an array of nodes)
             # so we parse then try get the children.
             $parsed = $tree->parse($context);
             if (!is_array($parsed) && isset($parsed->children)) {
                 $parsed = $parsed->children;
             }
             if (is_array($parsed)) {
                 $imported = array_merge($imported, $parsed);
             }
         }
     }
     return $imported;
 }
 /**
  * Get imported files
  *
  * @param SassParser $parser The current parser
  *
  * @return String[] All imported files
  */
 public function getFiles($parser)
 {
     $files = array();
     foreach ($this->files as $file) {
         if (preg_match(self::MATCH_CSS, $file, $matches)) {
             if (isset($matches[2]) && $matches[2] == 'url') {
                 $file = $matches[1];
             } else {
                 $file = "url('{$file}')";
             }
             return array(new SassString("@import {$file};"), new SassString("\n"));
         }
         $file = trim($file, '\'"');
         $files = array_merge(SassFile::get_file($file, $parser), $files);
     }
     return $files;
 }
예제 #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.
  * @param string name of source file or Sass source
  * @return SassRootNode Root node of document tree
  */
 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 = null;
         foreach ($source as $key => $value) {
             if (is_numeric($key)) {
                 $code = $value;
                 $type = true;
             } else {
                 $code = $key;
                 $type = $value;
             }
             if ($return === null) {
                 $return = $this->parse($code, $type);
             } else {
                 $newNode = $this->parse($code, $type);
                 foreach ($newNode->children as $children) {
                     array_push($return->children, $children);
                 }
             }
         }
         return $return;
     }
     if ($isFile && ($files = SassFile::get_file($source, $this))) {
         $files_source = '';
         foreach ($files as $file) {
             $this->filename = $file;
             $this->syntax = substr(strrchr($file, '.'), 1);
             if ($this->syntax == SassFile::CSS) {
                 $this->property_syntax = "css";
             } elseif (!$this->property_syntax && $this->syntax == SassFile::SCSS) {
                 $this->property_syntax = "scss";
             }
             if ($this->syntax !== SassFile::SASS && $this->syntax !== SassFile::SCSS && $this->syntax !== SassFile::CSS) {
                 if ($this->debug) {
                     throw new SassException('Invalid {what}', array('{what}' => 'syntax option'));
                 }
                 return FALSE;
             }
             $files_source .= SassFile::get_file_contents($this->filename, $this);
         }
         return $this->toTree($files_source);
     } else {
         return $this->toTree($source);
     }
 }
예제 #4
0
 public static function compassUrl($path, $only_path = false, $web_path = true)
 {
     $opath = $path;
     if (!($path = SassFile::get_file($path, SassParser::$instance, false))) {
         throw new Exception('File not found: ' . $opath);
     }
     $path = $path[0];
     if ($web_path) {
         $webroot = realpath($_SERVER['DOCUMENT_ROOT']);
         $path = str_replace($webroot, '', $path);
     }
     if ($only_path) {
         return new SassString($path);
     }
     return new SassString("url('{$path}')");
 }
예제 #5
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.
  * @param string name of source file or Sass source
  * @return SassRootNode Root node of document tree
  */
 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(strrchr($file, '.'), 1);
             if ($this->syntax == SassFile::CSS) {
                 $this->property_syntax = "css";
             } elseif (!$this->property_syntax && $this->syntax == SassFile::SCSS) {
                 $this->property_syntax = "scss";
             }
             if ($this->syntax !== SassFile::SASS && $this->syntax !== SassFile::SCSS && $this->syntax !== SassFile::CSS) {
                 if ($this->debug) {
                     throw new SassException('Invalid {what}', array('{what}' => 'syntax option'));
                 }
                 return FALSE;
             }
             $files_source .= SassFile::get_file_contents($this->filename, $this);
         }
         return $this->toTree($files_source);
     } else {
         return $this->toTree($source);
     }
 }