Source of file LessphpFilter.php
Size: 3,736 Bytes - Last Modified: 2013-06-02T00:13:43+02:00
/home/theseer/Downloads/Symfony/vendor/kriswallsmith/assetic/src/Assetic/Filter/LessphpFilter.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151 | <?php /* * This file is part of the Assetic package, an OpenSky project. * * (c) 2010-2013 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\Factory\AssetFactory; use Assetic\Util\LessUtils; /** * Loads LESS files using the PHP implementation of less, lessphp. * * Less files are mostly compatible, but there are slight differences. * * @link http://leafo.net/lessphp/ * * @author David Buchmann <david@liip.ch> * @author Kris Wallsmith <kris.wallsmith@gmail.com> */ class LessphpFilter implements DependencyExtractorInterface { private $presets = array(); private $formatter; private $preserveComments; /** * Lessphp Load Paths * * @var array */ protected $loadPaths = array(); /** * Adds a load path to the paths used by lessphp * * @param string $path Load Path */ public function addLoadPath($path) { $this->loadPaths[] = $path; } /** * Sets load paths used by lessphp * * @param array $loadPaths Load paths */ public function setLoadPaths(array $loadPaths) { $this->loadPaths = $loadPaths; } public function setPresets(array $presets) { $this->presets = $presets; } /** * @param string $formatter One of "lessjs", "compressed", or "classic". */ public function setFormatter($formatter) { $this->formatter = $formatter; } /** * @param boolean $preserveComments */ public function setPreserveComments($preserveComments) { $this->preserveComments = $preserveComments; } public function filterLoad(AssetInterface $asset) { $root = $asset->getSourceRoot(); $path = $asset->getSourcePath(); $lc = new \lessc(); if ($root && $path) { $lc->importDir = dirname($root.'/'.$path); } foreach ($this->loadPaths as $loadPath) { $lc->addImportDir($loadPath); } if ($this->formatter) { $lc->setFormatter($this->formatter); } if (null !== $this->preserveComments) { $lc->setPreserveComments($this->preserveComments); } $asset->setContent($lc->parse($asset->getContent(), $this->presets)); } public function filterDump(AssetInterface $asset) { } public function getChildren(AssetFactory $factory, $content, $loadPath = null) { $loadPaths = $this->loadPaths; if (null !== $loadPath) { $loadPaths[] = $loadPath; } if (empty($loadPaths)) { return array(); } $children = array(); foreach (LessUtils::extractImports($content) as $reference) { if ('.css' === substr($reference, -4)) { // skip normal css imports // todo: skip imports with media queries continue; } if ('.less' !== substr($reference, -5)) { $reference .= '.less'; } foreach ($loadPaths as $loadPath) { if (file_exists($file = $loadPath.'/'.$reference)) { $coll = $factory->createAsset($file, array(), array('root' => $loadPath)); foreach ($coll as $leaf) { $leaf->ensureFilter($this); $children[] = $leaf; goto next_reference; } } } next_reference: } return $children; } } |