From 2cb9577ca2cf23bf6f13c4a9ba4d27d27b48c57c Mon Sep 17 00:00:00 2001 From: Josh Sherman Date: Mon, 28 Jan 2013 16:59:44 -0500 Subject: [PATCH] Added SASS support Closes #12 --- classes/Dynamic.php | 36 +++++++++++++++++++++++++++--------- jar.php | 36 +++++++++++++++++++++++++++--------- 2 files changed, 54 insertions(+), 18 deletions(-) diff --git a/classes/Dynamic.php b/classes/Dynamic.php index 118ae6a..ce1acf4 100644 --- a/classes/Dynamic.php +++ b/classes/Dynamic.php @@ -9,7 +9,7 @@ * Redistribution of these files must retain the above copyright notice. * * @author Josh Sherman - * @copyright Copyright 2007-2012, Josh Sherman + * @copyright Copyright 2007-2013, Josh Sherman * @license http://www.opensource.org/licenses/mit-license.html * @package PICKLES * @link https://github.com/joshtronic/pickles @@ -100,16 +100,18 @@ class Dynamic extends Object * Generate Stylesheet Reference * * Attempts to minify the stylesheet and then returns the reference URI for - * the file, minified or not. Supports LESS, pass it a .less file instead - * and it will be compiled before minification. + * the file, minified or not. Supports LESS and SASS, pass it a .less file + * or a .scss file instead and it will be compiled before minification. * * @param string $reference URI reference of the Stylesheet * @return string URI reference reference with dynamic content * @url http://lesscss.org + * @url http://sass-lang.com */ public function css($original_reference) { $less = false; + $sass = false; // Injects .min into the filename $parts = explode('.', $original_reference); @@ -122,10 +124,17 @@ class Dynamic extends Object { end($parts); - if (current($parts) == 'less') + switch (current($parts)) { - $less = true; - $parts[key($parts)] = 'css'; + case 'less': + $less = true; + $parts[key($parts)] = 'css'; + break; + + case 'scss': + $sass = true; + $parts[key($parts)] = 'css'; + break; } $parts[key($parts)] = 'min.' . current($parts); @@ -154,12 +163,21 @@ class Dynamic extends Object */ if ($this->config->pickles['minify'] === true) { - // Compiles LESS to CSS before minifying - if ($less) + // Compiles LESS & SASS to CSS before minifying + if ($less || $sass) { $compiled_filename = str_replace('.min', '', $minified_filename); - exec('export PATH=$PATH:/usr/local/bin; ' . PICKLES_PATH . 'vendors/cloudhead/less.js/bin/lessc ' . $original_filename . ' > ' . $compiled_filename); + if ($less) + { + $command = 'export PATH=$PATH:/usr/local/bin; ' . PICKLES_PATH . 'vendors/cloudhead/less.js/bin/lessc ' . $original_filename . ' > ' . $compiled_filename; + } + elseif ($sass) + { + $command = 'sass ' . $original_filename . ':' . $compiled_filename; + } + + exec($command); $original_filename = $compiled_filename; } diff --git a/jar.php b/jar.php index d31290c..f1afc4d 100755 --- a/jar.php +++ b/jar.php @@ -3017,7 +3017,7 @@ class Distance * Redistribution of these files must retain the above copyright notice. * * @author Josh Sherman - * @copyright Copyright 2007-2012, Josh Sherman + * @copyright Copyright 2007-2013, Josh Sherman * @license http://www.opensource.org/licenses/mit-license.html * @package PICKLES * @link https://github.com/joshtronic/pickles @@ -3108,16 +3108,18 @@ class Dynamic extends Object * Generate Stylesheet Reference * * Attempts to minify the stylesheet and then returns the reference URI for - * the file, minified or not. Supports LESS, pass it a .less file instead - * and it will be compiled before minification. + * the file, minified or not. Supports LESS and SASS, pass it a .less file + * or a .scss file instead and it will be compiled before minification. * * @param string $reference URI reference of the Stylesheet * @return string URI reference reference with dynamic content * @url http://lesscss.org + * @url http://sass-lang.com */ public function css($original_reference) { $less = false; + $sass = false; // Injects .min into the filename $parts = explode('.', $original_reference); @@ -3130,10 +3132,17 @@ class Dynamic extends Object { end($parts); - if (current($parts) == 'less') + switch (current($parts)) { - $less = true; - $parts[key($parts)] = 'css'; + case 'less': + $less = true; + $parts[key($parts)] = 'css'; + break; + + case 'scss': + $sass = true; + $parts[key($parts)] = 'css'; + break; } $parts[key($parts)] = 'min.' . current($parts); @@ -3162,12 +3171,21 @@ class Dynamic extends Object */ if ($this->config->pickles['minify'] === true) { - // Compiles LESS to CSS before minifying - if ($less) + // Compiles LESS & SASS to CSS before minifying + if ($less || $sass) { $compiled_filename = str_replace('.min', '', $minified_filename); - exec('export PATH=$PATH:/usr/local/bin; ' . PICKLES_PATH . 'vendors/cloudhead/less.js/bin/lessc ' . $original_filename . ' > ' . $compiled_filename); + if ($less) + { + $command = 'export PATH=$PATH:/usr/local/bin; ' . PICKLES_PATH . 'vendors/cloudhead/less.js/bin/lessc ' . $original_filename . ' > ' . $compiled_filename; + } + elseif ($sass) + { + $command = 'sass ' . $original_filename . ':' . $compiled_filename; + } + + exec($command); $original_filename = $compiled_filename; }