private static function generateCSS( $force = false ) { $cli = eZCLI::instance(); $cli->output("\n Generating css files"); foreach ( glob('extension/*/design/*/stylesheets/*.less') as $lessFilePath ) { $lessFile = new KLessFile($lessFilePath); if ( $force ) { $lessFile->compile(); } else { $lessFile->compileIfNeeded(); } } }
/** * @param array $lessFiles less files to compile * @param string $media * @param string $cacheIdentifier identifier used to prefix the cache entry for the packer */ public static function generateCssTag( $lessFiles, $media, $cacheIdentifier = null ) { if ( !is_array( $lessFiles ) ) { $lessFiles = array( $lessFiles ); } if ( is_null( $cacheIdentifier ) ) { $lessFilePaths = array(); foreach ( $lessFiles as $lessFile ) { $kLessFile = new KLessFile( $lessFile ); $lessFilePaths[] = $kLessFile->getCssFilePath(); } $cacheIdentifier = md5(json_encode($lessFilePaths)); } if ( empty($lessFiles) ) { return; } $timestamp = 0; /** @var array(KLessFile) $kLessFiles */ $kLessFiles = array(); foreach ( $lessFiles as $lessFileName ) { $kLessFile = new KLessFile( $lessFileName ); $timestamp = max( $timestamp, filemtime($kLessFile->getLessFilePath()) ); $kLessFiles[] = $kLessFile; } if ( empty( $kLessFiles) ) { return; } $packFilePath = eZSys::cacheDirectory() . '/public/stylesheets/k' . $cacheIdentifier . '_' . $timestamp . '.css'; $clusterFile = eZClusterFileHandler::instance( $packFilePath ); if ( !$clusterFile->exists() ) { $css = ''; foreach( $kLessFiles as $kLessFile ) { $css .= $kLessFile->cssContent(); } $clusterFile->storeContents( $css, 'klesspack', 'text/css' ); KLessCache::cssPackCacheCleanUp( $cacheIdentifier ); } $tag = '<link rel="stylesheet" type="text/css" href="/' . $packFilePath . '" '; if ( $media ) { $tag .= 'media="'.$media.'" '; } $tag .= "/>\n"; return $tag; }