forked from kriswallsmith/assetic
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3333d37
commit 3a059bc
Showing
6 changed files
with
130 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Assetic package, an OpenSky project. | ||
* | ||
* (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\FilterInterface; | ||
|
||
/** | ||
* Loads CssCrush files. | ||
* | ||
* @link http://the-echoplex.net/csscrush/ | ||
* @author Kris Wallsmith <kris.wallsmith@gmail.com> | ||
* | ||
* @todo import directives do not work | ||
*/ | ||
class CssCrushFilter implements FilterInterface | ||
{ | ||
private $debug = false; | ||
private $boilerplate; | ||
private $versioning = false; | ||
|
||
public function setDebug($debug) | ||
{ | ||
$this->debug = $debug; | ||
} | ||
|
||
public function setBoilerplate($boilerplate) | ||
{ | ||
$this->boilerplate = $boilerplate; | ||
} | ||
|
||
public function setVersioning($versioning) | ||
{ | ||
$this->versioning = $versioning; | ||
} | ||
|
||
public function filterLoad(AssetInterface $asset) | ||
{ | ||
$options = array(); | ||
|
||
if (null !== $this->debug) { | ||
$options['debug'] = (Boolean) $this->debug; | ||
} | ||
|
||
if (null !== $this->boilerplate) { | ||
$options['boilerplate'] = (Boolean) $this->boilerplate; | ||
} | ||
|
||
if (null !== $this->versioning) { | ||
$options['versioning'] = (Boolean) $this->versioning; | ||
} | ||
|
||
// remember the previous document root | ||
$snapshot = \CssCrush::$config->docRoot; | ||
|
||
// setup the input | ||
$input = tempnam(sys_get_temp_dir(), 'assetic_csscrush'); | ||
file_put_contents($input, $asset->getContent()); | ||
|
||
// process the asset | ||
\CssCrush::$config->docRoot = dirname($input); | ||
$output = \CssCrush::file('/'.basename($input), $options); | ||
$asset->setContent(file_get_contents(\CssCrush::$config->docRoot.$output)); | ||
|
||
// cleanup | ||
unlink($input); | ||
unlink(\CssCrush::$config->docRoot.$output); | ||
\CssCrush::$config->docRoot = $snapshot; | ||
} | ||
|
||
public function filterDump(AssetInterface $asset) | ||
{ | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Assetic package, an OpenSky project. | ||
* | ||
* (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\Test\Filter; | ||
|
||
use Assetic\Asset\FileAsset; | ||
use Assetic\Filter\CssCrushFilter; | ||
|
||
/** | ||
* @group integration | ||
*/ | ||
class CssCrushFilterTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
protected function setUp() | ||
{ | ||
if (!class_exists('CssCrush', false)) { | ||
$this->markTestSkipped('CssCrush is not available.'); | ||
} | ||
} | ||
|
||
public function testLoad() | ||
{ | ||
$asset = new FileAsset(__DIR__.'/fixtures/csscrush/main.css', array(), __DIR__.'/fixtures/csscrush', 'main.css'); | ||
$asset->load(); | ||
|
||
$filter = new CssCrushFilter(); | ||
$filter->filterLoad($asset); | ||
|
||
$this->assertContains('strong { font-weight: bold; }', $asset->getContent(), '->filterLoad() calls CssCrush'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
@import url("more.css"); | ||
body { color: red; } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
strong { font-weight: bold; } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters