From 97c96eadfb2941c4b1b5afe483731454bc9c9023 Mon Sep 17 00:00:00 2001 From: Josh Schmidt Date: Fri, 20 Sep 2013 11:19:55 -0600 Subject: [PATCH] Update README.md Add Less_Cache example --- README.md | 36 +++++++++++++++++++++++++----------- 1 file changed, 25 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index ef1af44e..ad515ee0 100644 --- a/README.md +++ b/README.md @@ -62,29 +62,29 @@ $css = $parser->getCss(); ``` -### Getting Info About The Parsed Files -php.less can tell you which .less files were imported and parsed. +### Caching CSS +Use the Less_Cache class to save and reuse the results of compiled less files. +This method we check the modified time of each less file (including imported files) and regenerate when changes are found. +Note: When changes are found, this method will return a different file name for the new cached content. ```php parseFile( '/var/www/mysite/bootstrap.less', '/mysite/' ); -$css = $parser->getCss(); -$imported_files = $parser->allParsedFiles(); +$to_cache = array( '/var/www/mysite/bootstrap.less' => '/mysite/' ); +Less_Cache::$cache_dir = '/var/www/writable_folder'; +$css_file_name = Less_Cache::Get( $to_cache ); +$compiled = file_get_contents( '/var/www/writable_folder/'.$css_file_name ); ``` -### Caching to Improve Performance -php.less will save serialized parser data for each .less file if a writable folder is passed to the SetCacheDir() method. -Note: This feature only caches intermediate parsing results to improve the performance of repeated css generation. -Your application should cache any css generated by php.less. +### Getting Info About The Parsed Files +php.less can tell you which .less files were imported and parsed. ```php SetCacheDir( '/var/www/writable_folder' ); $parser->parseFile( '/var/www/mysite/bootstrap.less', '/mysite/' ); $css = $parser->getCss(); +$imported_files = $parser->allParsedFiles(); ``` @@ -114,6 +114,20 @@ $css = $parser->getCss(); ``` +### Parser Caching +php.less will save serialized parser data for each .less file if a writable folder is passed to the SetCacheDir() method. +Note: This feature only caches intermediate parsing results to improve the performance of repeated css generation. +Your application should cache any css generated by php.less. + +```php +SetCacheDir( '/var/www/writable_folder' ); +$parser->parseFile( '/var/www/mysite/bootstrap.less', '/mysite/' ); +$css = $parser->getCss(); +``` + + credits --- php.less was originally ported to php by [Matt Agar](https://github.com/agar) and then updated by [Martin Jantošovič](https://github.com/Mordred).