From 26f735d407376b570cf4da1688d6758f808c4604 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pavel=20Z=CC=8Celezny=CC=81?= Date: Fri, 11 Dec 2015 09:08:52 +0100 Subject: [PATCH] Support for import from absolute path via ScssFilter --- WebLoader/Filter/ScssFilter.php | 2 +- tests/Filter/ScssFilterTest.php | 13 +++++++++++++ tests/fixtures/styleAbsolute.scss | 19 +++++++++++++++++++ tests/fixtures/styleAbsolute.scss.expected | 12 ++++++++++++ 4 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 tests/fixtures/styleAbsolute.scss create mode 100644 tests/fixtures/styleAbsolute.scss.expected diff --git a/WebLoader/Filter/ScssFilter.php b/WebLoader/Filter/ScssFilter.php index 568079e..9dedb91 100644 --- a/WebLoader/Filter/ScssFilter.php +++ b/WebLoader/Filter/ScssFilter.php @@ -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); } diff --git a/tests/Filter/ScssFilterTest.php b/tests/Filter/ScssFilterTest.php index fe326fc..3d254ae 100644 --- a/tests/Filter/ScssFilterTest.php +++ b/tests/Filter/ScssFilterTest.php @@ -6,6 +6,7 @@ use WebLoader\DefaultOutputNamingConvention; use WebLoader\FileCollection; use WebLoader\Filter\ScssFilter; +use WebLoader\Filter\VariablesFilter; class ScssFilterTest extends \PHPUnit_Framework_TestCase { @@ -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); + } + } diff --git a/tests/fixtures/styleAbsolute.scss b/tests/fixtures/styleAbsolute.scss new file mode 100644 index 0000000..e4ed002 --- /dev/null +++ b/tests/fixtures/styleAbsolute.scss @@ -0,0 +1,19 @@ + +@import '{{$fixturesAbsolutePath}}/style2.scss'; + +.navigation { + ul { + line-height: 20px; + color: blue; + a { + color: red; + } + } +} + +.footer { + .copyright { + color: silver; + } +} + diff --git a/tests/fixtures/styleAbsolute.scss.expected b/tests/fixtures/styleAbsolute.scss.expected new file mode 100644 index 0000000..d4249e7 --- /dev/null +++ b/tests/fixtures/styleAbsolute.scss.expected @@ -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; }