Created
February 27, 2014 22:16
-
-
Save duskohu/9260801 to your computer and use it in GitHub Desktop.
LessFilter
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
<?php | |
namespace NasExt\Framework\Components\WebLoader\Filter; | |
use WebLoader\Compiler; | |
/** | |
* @author Dusan Hudak <[email protected]> | |
*/ | |
class LessFilter | |
{ | |
/** @var \Less_Parser */ | |
private $parser; | |
/** | |
* @param \Less_Parser $parser | |
*/ | |
public function __construct(\Less_Parser $parser = NULL) | |
{ | |
$this->parser = new \Less_Parser(); | |
} | |
/** | |
* @return \Less_Parser | |
*/ | |
private function getLessC() | |
{ | |
// lazy loading | |
if (empty($this->parser)) { | |
$this->parser = new \Less_Parser(); | |
} | |
return $this->parser; | |
} | |
/** | |
* Invoke filter | |
* @param string $code | |
* @param \WebLoader\Compiler $loader | |
* @param string $file | |
* @return string | |
*/ | |
public function __invoke($code, Compiler $loader, $file) | |
{ | |
if (pathinfo($file, PATHINFO_EXTENSION) === 'less') { | |
$this->getLessC()->parseFile($file); | |
return $this->getLessC()->getCss(); | |
} | |
return $code; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment