Skip to content

Instantly share code, notes, and snippets.

@lsmith77
Created October 6, 2010 13:39
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lsmith77/613352 to your computer and use it in GitHub Desktop.
Save lsmith77/613352 to your computer and use it in GitHub Desktop.
<?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