diff --git a/library/Icinga/Web/LessCompiler.php b/library/Icinga/Web/LessCompiler.php index 01b441dc6..3cea4b073 100644 --- a/library/Icinga/Web/LessCompiler.php +++ b/library/Icinga/Web/LessCompiler.php @@ -29,12 +29,14 @@ namespace Icinga\Web; -use \Exception; -use \RecursiveDirectoryIterator; -use \RecursiveIteratorIterator; -use \RegexIterator; -use \RecursiveRegexIterator; -use \Zend_Controller_Front; +use Exception; +use RecursiveDirectoryIterator; +use RecursiveIteratorIterator; +use RegexIterator; +use RecursiveRegexIterator; +use Zend_Controller_Front; +use Icinga\Application\Icinga; +use lessc; /** * Less compiler prints files or directories to stdout @@ -56,6 +58,8 @@ class LessCompiler private $lessc; private $baseUrl; + + private $source; /** * Create a new instance @@ -63,7 +67,7 @@ class LessCompiler public function __construct() { require_once 'vendor/lessphp/lessc.inc.php'; - $this->lessc = new \lessc(); + $this->lessc = new lessc(); $this->lessc->setVariables( array( @@ -72,6 +76,13 @@ class LessCompiler ); } + public function compress() + { + $this->lessc->setPreserveComments(false); + $this->lessc->setFormatter('compressed'); + return $this; + } + /** * Add usable style item to stack * @@ -82,6 +93,51 @@ class LessCompiler $this->items[] = $item; } + public function addLoadedModules() + { + foreach (Icinga::app()->getModuleManager()->getLoadedModules() as $name => $module) { + $this->addModule($name, $module); + } + return $this; + } + + public function addFile($filename) + { + $this->source .= "\n/* CSS: $filename */\n" + . file_get_contents($filename) + . "\n\n"; + return $this; + } + + public function compile() + { + //TODO: +/* $tmpfile = '/tmp/icinga.less'; + $cssfile = '/tmp/icinga.css'; + if (! file_exists($tmpfile)) { + file_put_contents($tmpfile, $this->source); + } + if ($this->lessc->checkedCompile($tmpfile, $cssfile)) { + } + return file_get_contents($cssfile); +*/ + return $this->lessc->compile($this->source); + } + + public function addModule($name, $module) + { + if ($module->hasCss()) { + $this->source .= "\n/* CSS: modules/$name/module.less */\n" + . '.icinga-module.module-' + . $name + . " {\n" + . file_get_contents($module->getCssFilename()) + . "}\n\n" + ; + } + return $this; + } + /** * Compile and print a single file *