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 LESS files using the PHP implementation of less, lessphp. |
---|
18 | * |
---|
19 | * Less files are mostly compatible, but there are slight differences. |
---|
20 | * |
---|
21 | * @link http://leafo.net/lessphp/ |
---|
22 | * |
---|
23 | * @author David Buchmann <david@liip.ch> |
---|
24 | * @author Kris Wallsmith <kris.wallsmith@gmail.com> |
---|
25 | */ |
---|
26 | class LessphpFilter implements FilterInterface |
---|
27 | { |
---|
28 | private $presets = array(); |
---|
29 | |
---|
30 | /** |
---|
31 | * Lessphp Load Paths |
---|
32 | * |
---|
33 | * @var array |
---|
34 | */ |
---|
35 | protected $loadPaths = array(); |
---|
36 | |
---|
37 | /** |
---|
38 | * Adds a load path to the paths used by lessphp |
---|
39 | * |
---|
40 | * @param string $path Load Path |
---|
41 | */ |
---|
42 | public function addLoadPath($path) |
---|
43 | { |
---|
44 | $this->loadPaths[] = $path; |
---|
45 | } |
---|
46 | |
---|
47 | public function setPresets(array $presets) |
---|
48 | { |
---|
49 | $this->presets = $presets; |
---|
50 | } |
---|
51 | |
---|
52 | public function filterLoad(AssetInterface $asset) |
---|
53 | { |
---|
54 | $root = $asset->getSourceRoot(); |
---|
55 | $path = $asset->getSourcePath(); |
---|
56 | |
---|
57 | $lc = new \lessc(); |
---|
58 | if ($root && $path) { |
---|
59 | $lc->importDir = dirname($root.'/'.$path); |
---|
60 | } |
---|
61 | foreach ($this->loadPaths as $loadPath) { |
---|
62 | $lc->addImportDir($loadPath); |
---|
63 | } |
---|
64 | |
---|
65 | $asset->setContent($lc->parse($asset->getContent(), $this->presets)); |
---|
66 | } |
---|
67 | |
---|
68 | public function filterDump(AssetInterface $asset) |
---|
69 | { |
---|
70 | } |
---|
71 | } |
---|