Skip to content

Instantly share code, notes, and snippets.

@jlogsdon
Created September 1, 2009 18:51
Show Gist options
  • Save jlogsdon/179301 to your computer and use it in GitHub Desktop.
Save jlogsdon/179301 to your computer and use it in GitHub Desktop.
<?php
/**
* This script should be passed a GET parameter named "file" with the relative path
* to the .less file.
*
* If .css is used instead of .less, it will be replaced with .less when looking for
* the file.
*
* I personally use an internal redirect that matches the .css extension and rewrites
* it to this script. Saving the processed .less as a .css is a good idea if you
* have a heavily trafficked website.
*/
// Set this to where you did the path that contains small_css.php. If you cloned the repository
// in the same directory as this script, leave as is.
define('SMALL_CSS_DIR', './small-css/lib');
header("Content-type: text/css");
$file = isset($_GET["file"]) ? str_replace(".css", ".less", $_GET["file"]) : null;
$dir = substr($file, 0, strrpos($file, "/") + 1);
if (is_null($file) || !is_file($file)) {
header("HTTP/1.1 404 Not Found");
exit;
}
require_once SMALL_CSS_DIR."/small_css.php";
$css = new SmallCss($dir);
$css->parse(file_get_contents($file));
$css->output();
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment