Browse files

Fixed relative import of Sass files by giving the priority to relativ…

…e paths from current file over load paths.

--HG--
branch : stable
  • Loading branch information...
1 parent bdca8ef commit a220068fd919b76dfcc98c6e8de1653774ad1fa2 @ludovicchabant committed Nov 23, 2011
Showing with 13 additions and 8 deletions.
  1. +8 −4 _piecrust/libs/PhamlP/sass/SassFile.php
  2. +5 −4 _piecrust/libs/PhamlP/sass/tree/SassImportNode.php
View
12 _piecrust/libs/PhamlP/sass/SassFile.php
@@ -48,7 +48,9 @@ public static function getTree($filename, $parser) {
/**
* Returns the full path to a file to parse.
- * The file is looked for recursively under the load_paths directories and
+ * If a relative directory is given, a filename relative to that directory
+ * is tried first.
+ * Then, the file is looked for recursively under the load_paths directories and
* the template_location directory.
* 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.
@@ -57,7 +59,7 @@ public static function getTree($filename, $parser) {
* @return string path to file
* @throws SassException if file not found
*/
- public static function getFile($filename, $parser) {
+ public static function getFile($filename, $parser, $relativeDir = null) {
$ext = substr($filename, -5);
foreach (self::$extensions as $i=>$extension) {
@@ -79,7 +81,9 @@ public static function getFile($filename, $parser) {
$paths = $parser->load_paths;
if(!empty($parser->filename))
- $paths[] = dirname($parser->filename);
+ array_splice($paths, 0, 0, dirname($parser->filename));
+ if ($relativeDir)
+ array_splice($paths, 0, 0, $relativeDir);
foreach($paths as $loadPath) {
$path = self::findFile($_filename, realpath($loadPath));
if ($path !== false) {
@@ -164,4 +168,4 @@ public static function setCachedFile($sassc, $filename, $cacheLocation) {
return file_put_contents($cached, serialize($sassc));
}
-}
+}
View
9 _piecrust/libs/PhamlP/sass/tree/SassImportNode.php
@@ -53,9 +53,10 @@ public function parse($context) {
return "@import {$file}";
}
else {
- $file = trim($file, '\'"');
- $tree = SassFile::getTree(
- SassFile::getFile($file, $this->parser), $this->parser);
+ $file = trim($file, '\'"');
+ $relativeDir = dirname($this->token->filename);
+ $path = SassFile::getFile($file, $this->parser, $relativeDir);
+ $tree = SassFile::getTree($path, $this->parser);
if (empty($tree)) {
throw new SassImportNodeException('Unable to create document tree for {file}', array('{file}'=>$file), $this);
}
@@ -66,4 +67,4 @@ public function parse($context) {
}
return $imported;
}
-}
+}

0 comments on commit a220068

Please sign in to comment.