ez projects / ezless / forum / general / useonefile does not work wi...
You need to be logged in to post messages in the forums. New users may register here.
Member since: Posts: 4 |
Wednesday 28 March 2012 5:36:52 pm Hello,
Trying to use ezless with twitter bootstrap & useOneFile=true The @import "..."; LESS include is ignored, because each CSS file sould be processed before a final merge (for now, the PHP code merge the CSS files first, and parse an unique CSS text at the end). Here is my code refactoring for solving that : private function generateTag( $files ){ eZDebug::writeDebug($files, 'ezLessOperator::generateTag'); $html = $cssContent = ''; $ini = eZINI::instance( 'ezless.ini' ); $useOneFile = $ini->variable( 'ezlessconfig','useOneFile' ); // ToDo: siteaccess as parameter $bases = eZTemplateDesignResource::allDesignBases(); $triedFiles = array(); $sys = eZSys::instance(); $path = $sys->cacheDirectory() . '/public/stylesheets'; require_once dirname( __FILE__ ) . '/../lib/lessphp/lessc.inc.php'; $packerLevel = $this->getPackerLevel(); $less = new lessc(); foreach( $files as $file){ $match = eZTemplateDesignResource::fileMatch( $bases, '', 'stylesheets/'.$file, $triedFiles ); $less->importDir = dirname( $match['path'] ); $content = file_get_contents( $match['path'] ); try { $parsedContent = $less->parse( $content ); $parsedContent = ezjscPacker::fixImgPaths( $parsedContent, $match['path'] ); if( $packerLevel > 1 ) { $parsedContent = $this->optimizeCSS( $parsedContent, $packerLevel ); } if( $useOneFile == "true" ){ $cssContent = $cssContent . PHP_EOL . $parsedContent; }else{ $file = md5(uniqid(mt_rand(), true)) . ".css"; $file = $path . '/' . $file; $clusterFile = eZClusterFileHandler::instance( $file ); $clusterFile->storeContents( $parsedContent, 'ezless', 'text/css' ); eZURI::transformURI( $file, true ); $html .= '<link rel="stylesheet" type="text/css" href="' . $file . '" />' . PHP_EOL; } } catch( Exception $e ) { eZDebug::writeError( $e->getMessage(), 'ezLessOperator for ' . $match['path'] ); } } if( $useOneFile == "true" ){ try { $file = md5(uniqid(mt_rand(), true)) . ".css"; $file = $path . '/' . $file; $clusterFile = eZClusterFileHandler::instance( $file ); $clusterFile->storeContents( $cssContent, 'ezless', 'text/css' ); eZURI::transformURI( $file, true ); $html = '<link rel="stylesheet" type="text/css" href="' . $file . '" />' . PHP_EOL; } catch( Exception $e ) { eZDebug::writeError( $e->getMessage(), 'ezLessOperator parsing error' ); } } return $html; } -- |
You need to be logged in to post messages in the forums. New users may register here.