Added support for LESS
Dynamic class detects less files, compiles them to CSS then minifies it
This commit is contained in:
parent
353e96094b
commit
b05a1691f2
2 changed files with 62 additions and 10 deletions
|
@ -99,14 +99,18 @@ class Dynamic extends Object
|
||||||
/**
|
/**
|
||||||
* Generate Stylesheet Reference
|
* Generate Stylesheet Reference
|
||||||
*
|
*
|
||||||
* Attempts to minify the stylesheet and then returns the reference URI
|
* Attempts to minify the stylesheet and then returns the reference URI for
|
||||||
* for the file, minified or not.
|
* the file, minified or not. Supports LESS, pass it a .less file instead
|
||||||
|
* and it will be compiled before minification.
|
||||||
*
|
*
|
||||||
* @param string $reference URI reference of the Stylesheet
|
* @param string $reference URI reference of the Stylesheet
|
||||||
* @return string URI reference reference with dynamic content
|
* @return string URI reference reference with dynamic content
|
||||||
|
* @url http://lesscss.org
|
||||||
*/
|
*/
|
||||||
public function css($original_reference)
|
public function css($original_reference)
|
||||||
{
|
{
|
||||||
|
$less = false;
|
||||||
|
|
||||||
// Injects .min into the filename
|
// Injects .min into the filename
|
||||||
$parts = explode('.', $original_reference);
|
$parts = explode('.', $original_reference);
|
||||||
|
|
||||||
|
@ -117,6 +121,13 @@ class Dynamic extends Object
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
end($parts);
|
end($parts);
|
||||||
|
|
||||||
|
if (current($parts) == 'less')
|
||||||
|
{
|
||||||
|
$less = true;
|
||||||
|
$parts[key($parts)] = 'css';
|
||||||
|
}
|
||||||
|
|
||||||
$parts[key($parts)] = 'min.' . current($parts);
|
$parts[key($parts)] = 'min.' . current($parts);
|
||||||
$minified_reference = implode('.', $parts);
|
$minified_reference = implode('.', $parts);
|
||||||
}
|
}
|
||||||
|
@ -130,11 +141,23 @@ class Dynamic extends Object
|
||||||
{
|
{
|
||||||
$reference = $original_reference;
|
$reference = $original_reference;
|
||||||
|
|
||||||
if (is_writable($path) && (!file_exists($minified_filename) || filemtime($original_filename) > filemtime($minified_filename)) && $this->config->pickles['minify'] === true)
|
if (is_writable($path)
|
||||||
|
&& (!file_exists($minified_filename) || filemtime($original_filename) > filemtime($minified_filename))
|
||||||
|
&& $this->config->pickles['minify'] === true)
|
||||||
{
|
{
|
||||||
|
// Compiles LESS to CSS before minifying
|
||||||
|
if ($less)
|
||||||
|
{
|
||||||
|
$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);
|
||||||
|
|
||||||
|
$original_filename = $compiled_filename;
|
||||||
|
}
|
||||||
|
|
||||||
// Minifies CSS with a few basic character replacements.
|
// Minifies CSS with a few basic character replacements.
|
||||||
$stylesheet = file_get_contents($original_filename);
|
$stylesheet = file_get_contents($original_filename);
|
||||||
$stylesheet = str_replace(array("\t", "\n", ', ', ' {', ': ', ';}'), array('', '', ',', '{', ':', '}'), $stylesheet);
|
$stylesheet = str_replace(array("\t", "\n", ', ', ' {', ': ', ';}', ' '), array('', '', ',', '{', ':', '}', ''), $stylesheet);
|
||||||
$stylesheet = preg_replace('/\/\*.+?\*\//', '', $stylesheet);
|
$stylesheet = preg_replace('/\/\*.+?\*\//', '', $stylesheet);
|
||||||
file_put_contents($minified_filename, $stylesheet);
|
file_put_contents($minified_filename, $stylesheet);
|
||||||
|
|
||||||
|
@ -204,7 +227,10 @@ class Dynamic extends Object
|
||||||
{
|
{
|
||||||
$reference = $original_reference;
|
$reference = $original_reference;
|
||||||
|
|
||||||
if (is_writable($path) && (!file_exists($minified_filename) || filemtime($original_filename) > filemtime($minified_filename)) && extension_loaded('curl') && $this->config->pickles['minify'] === true)
|
if (is_writable($path)
|
||||||
|
&& (!file_exists($minified_filename) || filemtime($original_filename) > filemtime($minified_filename))
|
||||||
|
&& extension_loaded('curl')
|
||||||
|
&& $this->config->pickles['minify'] === true)
|
||||||
{
|
{
|
||||||
// Sets up the options list
|
// Sets up the options list
|
||||||
$options = array(
|
$options = array(
|
||||||
|
|
36
jar.php
36
jar.php
|
@ -2954,14 +2954,18 @@ class Dynamic extends Object
|
||||||
/**
|
/**
|
||||||
* Generate Stylesheet Reference
|
* Generate Stylesheet Reference
|
||||||
*
|
*
|
||||||
* Attempts to minify the stylesheet and then returns the reference URI
|
* Attempts to minify the stylesheet and then returns the reference URI for
|
||||||
* for the file, minified or not.
|
* the file, minified or not. Supports LESS, pass it a .less file instead
|
||||||
|
* and it will be compiled before minification.
|
||||||
*
|
*
|
||||||
* @param string $reference URI reference of the Stylesheet
|
* @param string $reference URI reference of the Stylesheet
|
||||||
* @return string URI reference reference with dynamic content
|
* @return string URI reference reference with dynamic content
|
||||||
|
* @url http://lesscss.org
|
||||||
*/
|
*/
|
||||||
public function css($original_reference)
|
public function css($original_reference)
|
||||||
{
|
{
|
||||||
|
$less = false;
|
||||||
|
|
||||||
// Injects .min into the filename
|
// Injects .min into the filename
|
||||||
$parts = explode('.', $original_reference);
|
$parts = explode('.', $original_reference);
|
||||||
|
|
||||||
|
@ -2972,6 +2976,13 @@ class Dynamic extends Object
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
end($parts);
|
end($parts);
|
||||||
|
|
||||||
|
if (current($parts) == 'less')
|
||||||
|
{
|
||||||
|
$less = true;
|
||||||
|
$parts[key($parts)] = 'css';
|
||||||
|
}
|
||||||
|
|
||||||
$parts[key($parts)] = 'min.' . current($parts);
|
$parts[key($parts)] = 'min.' . current($parts);
|
||||||
$minified_reference = implode('.', $parts);
|
$minified_reference = implode('.', $parts);
|
||||||
}
|
}
|
||||||
|
@ -2985,11 +2996,23 @@ class Dynamic extends Object
|
||||||
{
|
{
|
||||||
$reference = $original_reference;
|
$reference = $original_reference;
|
||||||
|
|
||||||
if (is_writable($path) && (!file_exists($minified_filename) || filemtime($original_filename) > filemtime($minified_filename)) && $this->config->pickles['minify'] === true)
|
if (is_writable($path)
|
||||||
|
&& (!file_exists($minified_filename) || filemtime($original_filename) > filemtime($minified_filename))
|
||||||
|
&& $this->config->pickles['minify'] === true)
|
||||||
{
|
{
|
||||||
|
// Compiles LESS to CSS before minifying
|
||||||
|
if ($less)
|
||||||
|
{
|
||||||
|
$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);
|
||||||
|
|
||||||
|
$original_filename = $compiled_filename;
|
||||||
|
}
|
||||||
|
|
||||||
// Minifies CSS with a few basic character replacements.
|
// Minifies CSS with a few basic character replacements.
|
||||||
$stylesheet = file_get_contents($original_filename);
|
$stylesheet = file_get_contents($original_filename);
|
||||||
$stylesheet = str_replace(array("\t", "\n", ', ', ' {', ': ', ';}'), array('', '', ',', '{', ':', '}'), $stylesheet);
|
$stylesheet = str_replace(array("\t", "\n", ', ', ' {', ': ', ';}', ' '), array('', '', ',', '{', ':', '}', ''), $stylesheet);
|
||||||
$stylesheet = preg_replace('/\/\*.+?\*\//', '', $stylesheet);
|
$stylesheet = preg_replace('/\/\*.+?\*\//', '', $stylesheet);
|
||||||
file_put_contents($minified_filename, $stylesheet);
|
file_put_contents($minified_filename, $stylesheet);
|
||||||
|
|
||||||
|
@ -3059,7 +3082,10 @@ class Dynamic extends Object
|
||||||
{
|
{
|
||||||
$reference = $original_reference;
|
$reference = $original_reference;
|
||||||
|
|
||||||
if (is_writable($path) && (!file_exists($minified_filename) || filemtime($original_filename) > filemtime($minified_filename)) && extension_loaded('curl') && $this->config->pickles['minify'] === true)
|
if (is_writable($path)
|
||||||
|
&& (!file_exists($minified_filename) || filemtime($original_filename) > filemtime($minified_filename))
|
||||||
|
&& extension_loaded('curl')
|
||||||
|
&& $this->config->pickles['minify'] === true)
|
||||||
{
|
{
|
||||||
// Sets up the options list
|
// Sets up the options list
|
||||||
$options = array(
|
$options = array(
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue