[7575] | 1 | <?php |
---|
| 2 | |
---|
| 3 | /* |
---|
| 4 | * This file is part of the Assetic package, an OpenSky project. |
---|
| 5 | * |
---|
| 6 | * (c) 2010-2012 OpenSky Project Inc |
---|
| 7 | * |
---|
| 8 | * For the full copyright and license information, please view the LICENSE |
---|
| 9 | * file that was distributed with this source code. |
---|
| 10 | */ |
---|
| 11 | |
---|
| 12 | namespace Assetic\Filter; |
---|
| 13 | |
---|
| 14 | use Assetic\Asset\AssetInterface; |
---|
| 15 | |
---|
| 16 | /** |
---|
| 17 | * Loads SCSS files using the PHP implementation of scss, scssphp. |
---|
| 18 | * |
---|
| 19 | * Scss files are mostly compatible, but there are slight differences. |
---|
| 20 | * |
---|
| 21 | * @link http://leafo.net/scssphp/ |
---|
| 22 | * |
---|
| 23 | * @author Bart van den Burg <bart@samson-it.nl> |
---|
| 24 | */ |
---|
| 25 | class ScssphpFilter implements FilterInterface |
---|
| 26 | { |
---|
| 27 | private $compass = false; |
---|
| 28 | |
---|
| 29 | private $importPaths = array(); |
---|
| 30 | |
---|
| 31 | public function enableCompass($enable = true) |
---|
| 32 | { |
---|
| 33 | $this->compass = (Boolean) $enable; |
---|
| 34 | } |
---|
| 35 | |
---|
| 36 | public function isCompassEnabled() |
---|
| 37 | { |
---|
| 38 | return $this->compass; |
---|
| 39 | } |
---|
| 40 | |
---|
| 41 | public function filterLoad(AssetInterface $asset) |
---|
| 42 | { |
---|
| 43 | $root = $asset->getSourceRoot(); |
---|
| 44 | $path = $asset->getSourcePath(); |
---|
| 45 | |
---|
| 46 | $lc = new \scssc(); |
---|
| 47 | if ($this->compass) { |
---|
| 48 | new \scss_compass($lc); |
---|
| 49 | } |
---|
| 50 | if ($root && $path) { |
---|
| 51 | $lc->addImportPath(dirname($root.'/'.$path)); |
---|
| 52 | } |
---|
| 53 | foreach ($this->importPaths as $path) { |
---|
| 54 | $lc->addImportPath($path); |
---|
| 55 | } |
---|
| 56 | |
---|
| 57 | $asset->setContent($lc->compile($asset->getContent())); |
---|
| 58 | } |
---|
| 59 | |
---|
| 60 | public function setImportPaths(array $paths) |
---|
| 61 | { |
---|
| 62 | $this->importPaths = $paths; |
---|
| 63 | } |
---|
| 64 | |
---|
| 65 | public function addImportPath($path) |
---|
| 66 | { |
---|
| 67 | $this->importPaths[] = $path; |
---|
| 68 | } |
---|
| 69 | |
---|
| 70 | public function filterDump(AssetInterface $asset) |
---|
| 71 | { |
---|
| 72 | } |
---|
| 73 | } |
---|