New router needs JavaScript and Stylesheet handlers fitting it's needs
This commit is contained in:
parent
b677a631f0
commit
5c89512e05
|
@ -25,15 +25,11 @@ class JavaScript
|
|||
);
|
||||
|
||||
protected static $vendorFiles = array(
|
||||
'js/vendor/jquery-2.1.0.min.js',
|
||||
'js/vendor/jquery.sparkline.min.js'
|
||||
// 'js/vendor/jquery-1.11.0',
|
||||
'js/vendor/jquery-2.1.0',
|
||||
'js/vendor/jquery.sparkline'
|
||||
);
|
||||
|
||||
public static function listFiles()
|
||||
{
|
||||
return array_merge(self::$vendorFiles, self::$jsFiles, self::listModuleFiles());
|
||||
}
|
||||
|
||||
public static function listModuleFiles()
|
||||
{
|
||||
$list = array();
|
||||
|
@ -46,18 +42,29 @@ class JavaScript
|
|||
}
|
||||
|
||||
public static function sendMinified()
|
||||
{
|
||||
return self::send(true);
|
||||
}
|
||||
|
||||
public static function send($minified = false)
|
||||
{
|
||||
header('Content-Type: application/javascript');
|
||||
$basedir = Icinga::app()->getBootstrapDirecory();
|
||||
|
||||
$js = $out = '';
|
||||
$min = $minified ? '.min' : '';
|
||||
|
||||
// TODO: Cache header
|
||||
header('Content-Type: text/css');
|
||||
header('Content-Type: application/javascript');
|
||||
$cacheFile = '/tmp/cache_icinga' . $min . '.js';
|
||||
if (file_exists($cacheFile)) {
|
||||
readfile($cacheFile);
|
||||
exit;
|
||||
}
|
||||
|
||||
// We do not minify vendor files
|
||||
foreach (self::$vendorFiles as $file) {
|
||||
$out .= file_get_contents($basedir . '/' . $file);
|
||||
$out .= file_get_contents($basedir . '/' . $file . $min . '.js');
|
||||
}
|
||||
|
||||
foreach (self::$jsFiles as $file) {
|
||||
|
@ -69,8 +76,13 @@ class JavaScript
|
|||
$js .= file_get_contents($module->getJsFilename());
|
||||
}
|
||||
}
|
||||
|
||||
$out .= Minifier::minify($js, array('flaggedComments' => false));
|
||||
if ($minified) {
|
||||
$out .= Minifier::minify($js, array('flaggedComments' => false));
|
||||
} else {
|
||||
$out .= $js;
|
||||
}
|
||||
// Not yet, this is for tests only. Waiting for Icinga\Web\Cache
|
||||
// file_put_contents($cacheFile, $out);
|
||||
echo $out;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -34,14 +34,35 @@ class StyleSheet
|
|||
return $less->compile();
|
||||
}
|
||||
|
||||
public static function send()
|
||||
public static function sendMinified()
|
||||
{
|
||||
self::send(true);
|
||||
}
|
||||
|
||||
public static function send($minified = false)
|
||||
{
|
||||
header('Content-Type: text/css');
|
||||
|
||||
$min = $minified ? '.min' : '';
|
||||
$cacheFile = '/tmp/cache_icinga' . $min . '.css';
|
||||
if (file_exists($cacheFile)) {
|
||||
readfile($cacheFile);
|
||||
exit;
|
||||
}
|
||||
|
||||
$less = new LessCompiler();
|
||||
$basedir = Icinga::app()->getBootstrapDirecory();
|
||||
foreach (self::$lessFiles as $file) {
|
||||
$less->addFile($basedir . '/' . $file);
|
||||
}
|
||||
echo $less->addLoadedModules()->compile();
|
||||
$less->addLoadedModules();
|
||||
if ($minified) {
|
||||
$less->compress();
|
||||
}
|
||||
$out = $less->compile();
|
||||
// Not yet, this is for tests only. Waiting for Icinga\Web\Cache
|
||||
// file_put_contents($cacheFile, $out);
|
||||
echo $out;
|
||||
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue