Created
May 8, 2012 22:08
-
-
Save miklschmidt/2639799 to your computer and use it in GitHub Desktop.
Cache that damn thing.. http://programming-perils.com/155/parse-less-files-on-the-fly-and-serve-them-as-css/
This file contains 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 | |
$css = $_GET['path']; | |
$less = str_replace(".css",".less",$css); | |
file_exists($less) and $compiled_css = str_replace(".css", filemtime($less) . ".css", $_GET['path']); | |
if (!empty($compiled_css) and !file_exists($compiled_css)) | |
{ | |
header("Content-type: text/css"); | |
$less_command = "/var/www/node/node_modules/less/bin/lessc ".realpath($less)." ".realpath($compiled_css); | |
shell_exec($less_command); | |
} | |
if (file_exists($compiled_css)) | |
{ | |
header("Content-type: text/css"); | |
$css_file = file_get_contents($compiled_css); | |
echo $css_file; | |
} | |
else | |
{ | |
# Just in case you haven't configured your error levels appropriately in you production env. | |
ob_start(); | |
trigger_error("couldn't find/compile $less"); | |
ob_end_clean(); | |
header("HTTP/1.0 404 Not Found"); | |
echo "Not Found"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Not tested.. should work though