Skip to content

Commit

Permalink
Support for import from absolute path via ScssFilter
Browse files Browse the repository at this point in the history
  • Loading branch information
zeleznypa committed Dec 11, 2015
1 parent 3a8e869 commit 26f735d
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 1 deletion.
2 changes: 1 addition & 1 deletion WebLoader/Filter/ScssFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ private function getScssC()
public function __invoke($code, \WebLoader\Compiler $loader, $file)
{
if (pathinfo($file, PATHINFO_EXTENSION) === 'scss') {
$this->getScssC()->setImportPaths(pathinfo($file, PATHINFO_DIRNAME) . '/');
$this->getScssC()->setImportPaths(array('', pathinfo($file, PATHINFO_DIRNAME) . '/'));
return $this->getScssC()->compile($code);
}

Expand Down
13 changes: 13 additions & 0 deletions tests/Filter/ScssFilterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use WebLoader\DefaultOutputNamingConvention;
use WebLoader\FileCollection;
use WebLoader\Filter\ScssFilter;
use WebLoader\Filter\VariablesFilter;

class ScssFilterTest extends \PHPUnit_Framework_TestCase
{
Expand All @@ -31,4 +32,16 @@ public function testReplace()
$this->assertSame(file_get_contents(__DIR__ . '/../fixtures/style.scss.expected'), $less);
}

public function testImportAbsolutePath()
{
$file = __DIR__ . '/../fixtures/styleAbsolute.scss';
$filter = new VariablesFilter(array(
'fixturesAbsolutePath' => realpath(__DIR__.'/../fixtures'),
));
$code = file_get_contents($file);
$filtered = $filter($code);
$less = $this->filter->__invoke($filtered, $this->compiler, $file);
$this->assertSame(file_get_contents(__DIR__ . '/../fixtures/styleAbsolute.scss.expected'), $less);
}

}
19 changes: 19 additions & 0 deletions tests/fixtures/styleAbsolute.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@

@import '{{$fixturesAbsolutePath}}/style2.scss';

.navigation {
ul {
line-height: 20px;
color: blue;
a {
color: red;
}
}
}

.footer {
.copyright {
color: silver;
}
}

12 changes: 12 additions & 0 deletions tests/fixtures/styleAbsolute.scss.expected
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
.clearFix {
display: block;
zoom: 1; }

.navigation ul {
line-height: 20px;
color: blue; }
.navigation ul a {
color: red; }

.footer .copyright {
color: silver; }

0 comments on commit 26f735d

Please sign in to comment.