X-Git-Url: http://git.roojs.org/?a=blobdiff_plain;f=AssetTrait.php;h=d71d81069f136fe991247ef100b34528039b3f6b;hb=d3fc56bf4a2e451d3b4d847adc5fa0fa04e8f563;hp=4075ee77d2e2244508926cea5f57ce04bb6f4511;hpb=907938d9101e33e9cf5d1c79c4a09dfd69d869b3;p=Pman.Core diff --git a/AssetTrait.php b/AssetTrait.php index 4075ee77..d71d8106 100644 --- a/AssetTrait.php +++ b/AssetTrait.php @@ -1,7 +1,7 @@ - +\n"; + return; + } //$path = $this->rootURL ."/Pman/$mod/"; @@ -51,6 +56,9 @@ trait Pman_Core_Asset_Trait { $mtime = 0; foreach($ar as $fn) { $f = basename($fn); + if (!preg_match('/\.js$/', $f) || $fn == '.js' || !file_exists($dir . '/' . $f)) { // only javascript files... (so XXX.Dialog.YYY* works..) + continue; + } // got the 'module file..' $mtime = filemtime($dir . '/'. $f); $maxtime = max($mtime, $maxtime); @@ -60,23 +68,17 @@ trait Pman_Core_Asset_Trait { ksort($arfiles); // just sort by name so it's consistant for serialize.. - $ui = posix_getpwuid(posix_geteuid()); - - - $compiledir = session_save_path() . '/' . - $ui['name'] . '-' . $ff->project . '-' . $ff->version . '-jscompile'; - - if (!file_exists($compiledir)) { - mkdir($compiledir,0700,true); - } + require_once 'Pman/Core/Asset.php'; + $compiledir = Pman_Core_Asset::getCompileDir('js', '', true); - $lsort = create_function('$a,$b','return strlen($a) > strlen($b) ? 1 : -1;'); + $lsort = function($a,$b) { return strlen($a) > strlen($b) ? 1 : -1; }; usort($files, $lsort); + $ff = HTML_FlexyFramework::get(); - if (!empty($this->bootLoader->isDev) && !empty($_REQUEST['isDev'])) { + if (!empty($ff->Pman['isDev']) && !empty($_REQUEST['isDev'])) { echo "\n"; $this->assetArrayToHtml($files,'js'); return; @@ -87,7 +89,8 @@ trait Pman_Core_Asset_Trait { $output = date('Y-m-d-H-i-s-', $maxtime). $smod .'-'.md5(serialize($arfiles)) .'.js'; - + + // where are we going to write all of this.. // This has to be done via a @@ -107,9 +110,11 @@ trait Pman_Core_Asset_Trait { } else { // echo "\n"; } + + $asset = $ff->project == 'Pman' ? '/Core/Asset/js/' : '/Asset/js/'; //$this->arrayToJsInclude( $files); $this->assetArrayToHtml( array( - $this->baseURL.'/Asset/js/'. $output, + $this->baseURL.$asset. $output, ), 'js'); @@ -127,17 +132,16 @@ trait Pman_Core_Asset_Trait { break; } - } } /** * usage in template - * {outputCssDir(#{Hydra/templates/images/css/#,#Hydra.js",#.......#)} + * {outputCSSDir(#{Hydra/templates/images/css/#,#Hydra.js",#.......#)} */ - function outputCssDir($path) + function outputCSSDir($path) { $relpath = $this->rootURL . '/' . $path .'/'; @@ -161,7 +165,10 @@ trait Pman_Core_Asset_Trait { } } - + if (empty($ar)) { + echo "\n"; + return; + } // cached version?? - how do we decide if it's expired? // while scanning the directory is slow... - it's faster than serving every file... @@ -204,24 +211,31 @@ trait Pman_Core_Asset_Trait { //print_r($relfiles); + + require_once 'Pman/Core/Asset.php'; + $compiledir = Pman_Core_Asset::getCompileDir('css', '', true); - $ui = posix_getpwuid(posix_geteuid()); - - - $compiledir = session_save_path() . '/' . - $ui['name'] . '-' . $ff->project . '-'. $ff->version . '-csscompile'; - + if (!file_exists($compiledir)) { mkdir($compiledir,0700,true); } - // no sorting??? - //$lsort = create_function('$a,$b','return strlen($a) > strlen($b) ? 1 : -1;'); - //usort($files, $lsort); - if (!empty($this->bootLoader->isDev) && !empty($_REQUEST['isDev'])) { + // yes sort... if includes are used - they have to be in the first file... + $lsort = function($a,$b ) { + return strlen($a) > strlen($b) ? 1 : -1; + }; + usort($files, $lsort); + usort($relfiles,$lsort); + // print_R($relfiles); + + $ff = HTML_FlexyFramework::get(); + + // isDev set + + if ((!empty($ff->Pman['isDev']) || $_SERVER['HTTP_HOST'] == 'localhost' )&& !empty($_REQUEST['isDev'])) { echo "\n"; $this->assetArrayToHtml($files,'css'); return; @@ -230,20 +244,20 @@ trait Pman_Core_Asset_Trait { $smod = str_replace('/','.',$path); - $output = date('Y-m-d-H-i-s-', $maxtime). $smod .'-'.md5(serialize($arfiles)) .'.css'; - + $output = date('Y-m-d-H-i-s-', $maxtime). $smod .'-'.md5(serialize(array($this->baseURL, $arfiles))) .'.css'; + $asset = $ff->project == 'Pman' ? '/Core/Asset/css/' : '/Asset/css/'; // where are we going to write all of this.. // This has to be done via a - if (true || !file_exists($compiledir.'/'.$output) || !filesize($compiledir.'/'.$output)) { - + if ( !file_exists($compiledir.'/'.$output) || !filesize($compiledir.'/'.$output)) { + //print_r($relfiles); require_once 'HTML/CSS/Minify.php'; $x = new HTML_CSS_Minify(substr($relpath,0,-1), $dir, $relfiles); - file_put_contents($compiledir.'/'.$output , $x->minify( $this->baseURL.'/Asset/css')); + file_put_contents($compiledir.'/'.$output , $x->minify( $this->baseURL.$asset)); clearstatcache(); if (!file_exists($compiledir.'/'.$output) || !filesize($compiledir.'/'.$routput)) { @@ -255,9 +269,11 @@ trait Pman_Core_Asset_Trait { } else { // echo "\n"; } + + //$this->arrayToJsInclude( $files); $this->assetArrayToHtml( array( - $this->baseURL.'/Asset/css/'. $output, + $this->baseURL.$asset. $output, ),'css'); @@ -265,4 +281,87 @@ trait Pman_Core_Asset_Trait { + function outputSCSS($smod) + { + // we cant output non-cached versions of this.... + $ff = HTML_FlexyFramework::get(); + $fp = "{$this->rootDir}/Pman/$smod/scss/{$smod}.scss"; + // var_dump($fp); + if (!file_exists($fp)) { + return; + } + + $ar = glob(dirname($fp) . '/*.scss'); + $maxtime = 0; + foreach($ar as $fn) { + $maxtime=max($maxtime, filemtime($fn)); + } + + + + //print_r($relfiles); + + require_once 'Pman/Core/Asset.php'; + $compiledir = Pman_Core_Asset::getCompileDir('css', '', true); + + + if (!file_exists($compiledir)) { + mkdir($compiledir,0700,true); + } + + + + + $output = date('Y-m-d-H-i-s-', $maxtime). $smod .'-'.md5(serialize(array($this->baseURL, $ar))) .'.css'; + + $asset = $ff->project == 'Pman' ? '/Core/Asset/css/' : '/Asset/css/'; + + // where are we going to write all of this.. + // This has to be done via a + + + + if ( !file_exists($compiledir.'/'.$output) || !filesize($compiledir.'/'.$output)) { + + + + require_once 'System.php'; + static $sassc = false; + if ($sassc === false) { + $sassc = System::which("sassc"); + } + if (empty($sassc)) { + die("INSTALL sassc"); + } + + $fd = dirname($fp); + + + $cmd = "{$sassc} --style=compressed --sourcemap=auto -I {$fd} -I {$this->rootDir}/roojs1/scss/bootstrap $smod.scss {$compiledir}/{$output}"; + //echo "$cmd\n"; echo `$cmd`; + `$cmd`; + + + clearstatcache(); + if (!file_exists($compiledir.'/'.$output) || + !filesize($compiledir.'/'.$routput)) { + echo "\n"; + echo "\n"; + return; + } + + } else { + // echo "\n"; + } + + + //$this->arrayToJsInclude( $files); + $this->assetArrayToHtml( array( + $this->baseURL.$asset. $output, + + ),'css'); + + } + + } \ No newline at end of file