From 460e0fe24201ddfaa58d8f9262067b48294fe2e6 Mon Sep 17 00:00:00 2001 From: Marius Hein Date: Wed, 16 Oct 2013 12:00:09 +0200 Subject: [PATCH] Implement on-the-fly less compilation refs #4892 --- application/controllers/StaticController.php | 33 ++++- application/layouts/scripts/layout.phtml | 11 +- library/Icinga/Application/Modules/Module.php | 4 +- library/Icinga/Web/LessCompiler.php | 121 ++++++++++++++++++ public/css.php | 23 ---- public/css/{ => icinga}/icons.css | 74 +++++------ public/css/{ => icinga}/main.css | 58 ++++----- 7 files changed, 219 insertions(+), 105 deletions(-) create mode 100644 library/Icinga/Web/LessCompiler.php delete mode 100644 public/css.php rename public/css/{ => icinga}/icons.css (57%) rename public/css/{ => icinga}/main.css (91%) diff --git a/application/controllers/StaticController.php b/application/controllers/StaticController.php index 0b7b088de..dd477d82e 100644 --- a/application/controllers/StaticController.php +++ b/application/controllers/StaticController.php @@ -141,10 +141,9 @@ class StaticController extends ActionController */ private function setCacheHeader($maxAge) { - $response = $this->getResponse(); - $response->setHeader('Cache-Control', 'max-age=3600', true); - $response->setHeader('Pragma', 'cache', true); - $response->setHeader( + $this->_response->setHeader('Cache-Control', 'max-age=3600', true); + $this->_response->setHeader('Pragma', 'cache', true); + $this->_response->setHeader( 'Expires', gmdate( 'D, d M Y H:i:s', @@ -153,5 +152,31 @@ class StaticController extends ActionController true ); } + + public function stylesheetAction() + { + $lessCompiler = new \Icinga\Web\LessCompiler(); + $moduleManager = Icinga::app()->getModuleManager(); + + $publicDir = realpath(dirname($_SERVER['SCRIPT_FILENAME'])); + + $lessCompiler->addItem($publicDir . '/css/vendor'); + $lessCompiler->addItem($publicDir . '/css/icinga'); + + foreach ($moduleManager->getLoadedModules() as $moduleName) { + $cssDir = $moduleName->getCssDir(); + + if (is_dir($cssDir)) { + $lessCompiler->addItem($cssDir); + } + } + + $this->_response->setHeader('Content-Type', 'text/css'); + $this->setCacheHeader(3600); + + $lessCompiler->printStack(); + + return; + } } // @codingStandardsIgnoreEnd diff --git a/application/layouts/scripts/layout.phtml b/application/layouts/scripts/layout.phtml index 533b42fd8..903cd84ff 100755 --- a/application/layouts/scripts/layout.phtml +++ b/application/layouts/scripts/layout.phtml @@ -16,16 +16,7 @@ - - - - - - - +