Permalink
Browse files

updated compass filter to use sass' --compass option

  • Loading branch information...
1 parent a6ebb68 commit 32b2cf2b9335723afbf64f3e6713a7851bff0377 @kriswallsmith committed Apr 25, 2011
View
@@ -14,7 +14,6 @@
<!-- <server name="NODE_PATH" value="/path/to/node/lib" /> -->
<!-- <server name="LESSPHP" value="/path/to/lessphp/lessc.inc.php" /> -->
<!-- <server name="SASS_BIN" value="/path/to/sass" /> -->
- <!-- <server name="COMPASS_BIN" value="/path/to/compass" /> -->
<!-- <server name="RUBY_BIN" value="/path/to/ruby" /> -->
<!-- <server name="SPROCKETS_LIB" value="/path/to/sprockets/lib" /> -->
<!-- <server name="TWIG_LIB" value="/path/to/twig/lib" /> -->
@@ -1,35 +1,31 @@
<?php
-namespace Assetic\Filter;
-
-use Assetic\Asset\AssetInterface;
-use Assetic\Filter\Sass\SassFilter;
-
/*
- * This file is part of the Assetic package.
+ * This file is part of the Assetic package, an OpenSky project.
*
- * (c) Kris Wallsmith <kris.wallsmith@gmail.com>
+ * (c) 2010-2011 OpenSky Project Inc
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
+namespace Assetic\Filter;
+
+use Assetic\Asset\AssetInterface;
+use Assetic\Filter\Sass\SassFilter;
+
/**
* Loads Compass files.
*
- * @see http://beta.compass-style.org/help/tutorials/command-line/
- * @see https://github.com/miracle2k/webassets/blob/master/src/webassets/filter/compass.py
+ * The Compass filter requires SASS >= 3.1.0.
+ *
* @author Maxime Thirouin <dev@moox.fr>
*/
class CompassFilter extends SassFilter
{
- public function __construct($sassPath = '/usr/bin/sass', $compassPath = '/usr/bin/compass')
+ public function __construct($sassPath = '/usr/bin/sass')
{
- parent::__construct($sassPath, $compassPath);
-
- // Compass does not allow us to add import path in command line
- // but we can do this with sass, with the new option --compass
- // @see http://groups.google.com/group/compass-users/browse_thread/thread/a476dfcd2b47653e
+ parent::__construct($sassPath);
$this->setCompass(true);
}
}
@@ -28,22 +28,20 @@ class SassFilter implements FilterInterface
const STYLE_COMPRESSED = 'compressed';
private $sassPath;
- private $compassPath;
private $unixNewlines;
private $scss;
- private $compass;
private $style;
private $quiet;
private $debugInfo;
private $lineNumbers;
private $loadPaths = array();
private $cacheLocation;
private $noCache;
+ private $compass;
- public function __construct($sassPath = '/usr/bin/sass', $compassPath = null)
+ public function __construct($sassPath = '/usr/bin/sass')
{
$this->sassPath = $sassPath;
- $this->compassPath = $compassPath;
$this->cacheLocation = sys_get_temp_dir();
}
@@ -57,11 +55,6 @@ public function setScss($scss)
$this->scss = $scss;
}
- public function setCompass($compass)
- {
- $this->compass = $compass;
- }
-
public function setStyle($style)
{
$this->style = $style;
@@ -97,6 +90,11 @@ public function setNoCache($noCache)
$this->noCache = $noCache;
}
+ public function setCompass($compass)
+ {
+ $this->compass = $compass;
+ }
+
public function filterLoad(AssetInterface $asset)
{
$options = array($this->sassPath);
@@ -109,28 +107,6 @@ public function filterLoad(AssetInterface $asset)
$options[] = '--scss';
}
- if ($this->compass) {
- //$options[] = '--compass'; // for sass > 3
-
- // basically, we just need to run sass with options '-r compass `compass imports`'
- // but because we use escapeshellarg, we have to preprocess the 'compass imports',
- // and explode as options, because it create options for sass
- $options[] = '-r';
- $options[] = 'compass';
-
- // we generate the appropriate -I paths to allow sass to parse files using compass
- // see "compass help imports"
- $proc = new Process($this->compassPath . ' imports');
- $code = $proc->run();
-
- if (0 < $code) {
- throw new \RuntimeException($proc->getErrorOutput());
- }
-
- // here is the trick because the ouput given by 'compass imports' is like "-I /path -I /path2"
- $options = array_merge($options, explode(' ', $proc->getOutput()));
- }
-
if ($this->style) {
$options[] = '--style';
$options[] = $this->style;
@@ -162,10 +138,15 @@ public function filterLoad(AssetInterface $asset)
$options[] = '--no-cache';
}
- // finally
+ if ($this->compass) {
+ $options[] = '--compass';
+ }
+
+ // input
$options[] = $input = tempnam(sys_get_temp_dir(), 'assetic_sass');
file_put_contents($input, $asset->getContent());
+ // output
$options[] = $output = tempnam(sys_get_temp_dir(), 'assetic_sass');
$proc = new Process(implode(' ', array_map('escapeshellarg', $options)));
@@ -1,9 +1,9 @@
<?php
/*
- * This file is part of the Assetic package.
+ * This file is part of the Assetic package, an OpenSky project.
*
- * (c) Kris Wallsmith <kris.wallsmith@gmail.com>
+ * (c) 2010-2011 OpenSky Project Inc
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
@@ -15,46 +15,54 @@
use Assetic\Filter\CompassFilter;
/**
- * Compass Filter test case
- *
+ * Compass filter test case.
+ *
* @author Maxime Thirouin <dev@moox.fr>
*/
class CompassFilterTest extends \PHPUnit_Framework_TestCase
{
- public function setUp()
+ protected function setUp()
{
- if (!isset($_SERVER['COMPASS_BIN']) or !isset($_SERVER['SASS_BIN'])) {
- $this->markTestSkipped('There is no COMPASS_BIN or SASS_BIN environment variable.');
+ if (!isset($_SERVER['SASS_BIN'])) {
+ $this->markTestSkipped('There is no SASS_BIN environment variable.');
}
}
public function testFilterLoadWithScss()
{
- $this->_testAsset(__DIR__ . '/fixtures/compass/stylesheet.scss');
+ $asset = new FileAsset(__DIR__.'/fixtures/compass/stylesheet.scss');
+ $asset->load();
+
+ $filter = new CompassFilter($_SERVER['SASS_BIN']);
+ $filter->addLoadPath(__DIR__.'/fixtures/compass');
+ $filter->setScss(true);
+ $filter->filterLoad($asset);
+
+ $this->assertContains('.test-class', $asset->getContent());
+ $this->assertContains('font-size: 2em;', $asset->getContent());
}
public function testFilterLoadWithSass()
{
- $this->_testAsset(__DIR__ . '/fixtures/compass/stylesheet.sass');
- }
-
- private function _testAsset($filePath)
- {
- $asset = new FileAsset($filePath);
+ $asset = new FileAsset(__DIR__.'/fixtures/compass/stylesheet.sass');
$asset->load();
- $filter = new CompassFilter();
- $filter->addLoadPath(dirname($filePath));
-
- // there is just a trick for selecting sass or scss (sass does not select the right syntax automatically)
- if (preg_match('#\.scss$#', $filePath))
- {
- $filter->setScss(true);
- }
-
+ $filter = new CompassFilter($_SERVER['SASS_BIN']);
+ $filter->addLoadPath(__DIR__.'/fixtures/compass');
$filter->filterLoad($asset);
$this->assertContains('.test-class', $asset->getContent());
$this->assertContains('font-size: 2em;', $asset->getContent());
}
+
+ public function testCompassMixin()
+ {
+ $asset = new FileAsset(__DIR__.'/fixtures/compass/compass.sass');
+ $asset->load();
+
+ $filter = new CompassFilter($_SERVER['SASS_BIN']);
+ $filter->filterLoad($asset);
+
+ $this->assertContains('text-decoration', $asset->getContent());
+ }
}
@@ -0,0 +1,4 @@
+@import "compass/typography/links/hover-link"
+
+a
+ @include hover-link

0 comments on commit 32b2cf2

Please sign in to comment.