Created
October 6, 2010 13:39
-
-
Save lsmith77/613352 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// put this into "dev/less/getcss.php" | |
// checkout lessphp into src/vendor: git clone git://github.com/leafo/lessphp.git | |
// add "Alias /dev/ /home/you/src/joiz/dev/" to your vhost | |
// add "RewriteRule ^main.css$ dev/less/getcss.php?cssfile=main [L]" to your vhost or .htaccess | |
// create app/config/main.less, use imports into your bundles (Resources/data/less/*) | |
// browse to http://[yourdomain]/main.css | |
$lessCompiler = __DIR__.'/../../src/vendor/lessphp/lessc.inc.php'; | |
if (!include $lessCompiler) { | |
echo "// less class definition not found: ".$lessCompiler; | |
exit; | |
} | |
if (empty($_GET['cssfile'])) { | |
echo "// cssfile GET parameter missing"; | |
exit; | |
} | |
if (!preg_match('/^[a-z_]+$/i', $_GET['cssfile'])) { | |
echo "// cssfile GET parameter illegal: ".$_GET['cssfile']; | |
exit; | |
} | |
$input = __DIR__.'/../../app/config/'.$_GET['cssfile'].'.less'; | |
$cacheFile = __DIR__.'/../../app/cache/dev/cache_'.$_GET['cssfile'].'.less'; | |
try { | |
$time = 0; | |
if (file_exists($cacheFile)) { | |
$input = unserialize(file_get_contents($cacheFile)); | |
$time = $input['updated']; | |
} | |
$cache = lessc::cexecute($input); | |
if ($time < $cache['updated']) { | |
file_put_contents($cacheFile, serialize($cache)); | |
} | |
echo $cache['compiled']; | |
} catch (exception $e) { | |
echo "// While compiling $input, encountered: ".$e->getMessage(); | |
exit; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment