/** * Outputs concatenated CSS for the specified view * @param string view | the view - optional */ public function css() { $this->setContentType('text/css; charset=utf-8;'); $this->setCache(Date::SPAN_MONTH); require_once Pimple::instance()->getBaseDir() . 'lib/Stylesheet.php'; $cacheDir = Pimple::instance()->getSiteDir() . 'cache/css/'; Dir::ensure($cacheDir); $templates = array(); if (!Request::get('skipLayout', false)) { $templates[] = 'application'; } $view = Request::get('view', false); if ($view) { $templates[] = $view; } $used = array(); $isDebug = Settings::get(Settings::DEBUG, false); foreach ($templates as $template) { $cacheFile = $cacheDir . $template . '.css'; echo "/* {$template} */\n"; if ($isDebug) { $view = new View($template); $files = $view->getInternalCssFiles(); echo "/*FILES:\n\t" . implode("\n\t", $files) . '*/' . chr(10); foreach ($files as $file) { if (in_array($file, $used) || String::StartsWith($file, "http://") || String::StartsWith($file, "https://")) { continue; } $used[] = $file; echo "/*FILE:" . basename($file) . '*/' . chr(10) . Stylesheet::minify($file) . chr(10); } } else { Dir::ensure(dirname($cacheFile)); if (!is_file($cacheFile)) { File::truncate($cacheFile); $view = new View($template); $files = $view->getInternalCssFiles(); File::append($cacheFile, "/*FILES:\n\t" . implode("\n\t", $files) . '*/' . chr(10)); foreach ($files as $file) { if (in_array($file, $used) || String::StartsWith($file, "http://") || String::StartsWith($file, "https://")) { continue; } $used[] = $file; File::append($cacheFile, "/*FILE:" . basename($file) . '*/' . chr(10) . Stylesheet::minify($file) . chr(10)); } } echo file_get_contents($cacheFile); } } Pimple::end(); }