Skip to content

Instantly share code, notes, and snippets.

@duskohu
Created February 27, 2014 22:16
Show Gist options
  • Save duskohu/9260801 to your computer and use it in GitHub Desktop.
Save duskohu/9260801 to your computer and use it in GitHub Desktop.
LessFilter
<?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