Skip to content

Commit

Permalink
Addition of sass compiler, update to readme, move all libraries to su…
Browse files Browse the repository at this point in the history
…bfolders to sidestep issue 35 without modifying plugin code
  • Loading branch information
stevenwoodson committed Jan 28, 2013
1 parent 7b057a4 commit 243f863
Show file tree
Hide file tree
Showing 62 changed files with 9,011 additions and 5,109 deletions.
6 changes: 3 additions & 3 deletions README.markdown
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# Simple Assets Library

A simple assets library that has the ability to combine and minify your JavaScript and CSS assets.
Additionally there's a <a href="http://leafo.net/lessphp/">LessCSS</a> compiler and a <a href="https://github.com/alxlit/coffeescript-php">CoffeeScript</a> compiler.
A simple assets library that has the ability to combine, minify and obfuscate your JavaScript and CSS assets.
Additionally there's a <a href="http://leafo.net/lessphp/">LessPHP</a> compiler, a <a href="https://github.com/richthegeek/phpsass">PHPSass</a> compiler and a <a href="https://github.com/alxlit/coffeescript-php">CoffeeScript</a> compiler.

## Third Party Libraries

The libraries <a href="https://github.com/rgrove/jsmin-php/">JSMin</a>, <a href="http://code.google.com/p/cssmin/">CSSMin</a>, <a href="http://leafo.net/lessphp/">LessPHP</a> and <a href="https://github.com/alxlit/coffeescript-php">CoffeeScript-PHP</a> are all created by third parties, but they're included in this package for convenience.
The libraries <a href="https://github.com/rgrove/jsmin-php/">JSMin</a>, <a href="http://code.google.com/p/cssmin/">CSSMin</a>, <a href="http://leafo.net/lessphp/">LessPHP</a>, <a href="https://github.com/richthegeek/phpsass">PHPSass</a>, <a href="http://joliclic.free.fr/php/javascript-packer/en/">JS Packer</a> and <a href="https://github.com/alxlit/coffeescript-php">CoffeeScript-PHP</a> are all created by third parties, but they're included in this package for convenience.

## Requirements

Expand Down
2 changes: 2 additions & 0 deletions config/assets.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@

$config['assets']['minify_css'] = true;
$config['assets']['minify_js'] = true;
$config['assets']['pack_js'] = true;
$config['assets']['enable_less'] = true;
$config['assets']['enable_sass'] = true;
$config['assets']['enable_coffeescript'] = true;
$config['assets']['freeze'] = false;

Expand Down
76 changes: 60 additions & 16 deletions libraries/assets.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class Assets {

protected static $_ci;
protected static $_less;
protected static $_sass;
protected static $_cache_info;
protected static $_cache_info_file = 'info.cache';
protected static $_enable_benchmark = false;
Expand Down Expand Up @@ -50,6 +51,7 @@ class Assets {
public static $auto_clear_js_cache = false; // Or just cached JS files
public static $html5 = true; // Use HTML5 tags
public static $enable_less = true; // Enable LESS CSS parser
public static $enable_sass = true; // Enable SASS CSS parser
public static $enable_coffeescript = true; // Enable CoffeeScript parser
public static $freeze = false; // Disable all processing once the assets are cached (for production)

Expand All @@ -64,6 +66,7 @@ class Assets {
private static $_jsmin_loaded = false;
private static $_jspacker_loaded = false;
private static $_less_loaded = false;
private static $_sass_loaded = false;
private static $_coffeescript_loaded = false;


Expand Down Expand Up @@ -387,6 +390,21 @@ private static function _process($type = null, $group = null)
$import_result = self::_process_imports($contents, null, $asset['file']);
$contents = $import_result['contents'];

list ( $asset['file_name'], $asset['file_ext']) = explode( '.', $asset['file'] );

// LESS
if (self::$enable_less and ! self::$freeze and $asset['file_ext'] == 'less')
{
self::_init_less();
$contents = self::$_less->parse($contents);
}
// SASS
if (self::$enable_sass and ! self::$freeze and ( $asset['file_ext'] == 'sass' or $asset['file_ext'] == 'scss' ))
{
self::_init_sass();
$contents = self::$_sass->toCss($contents);
}

// Update last modified time
if ($import_result['last_modified'] > self::$_assets[$type][$group]['last_modified'])
{
Expand Down Expand Up @@ -420,18 +438,11 @@ private static function _process($type = null, $group = null)
// New file name
$file_name = self::$_assets[$type][$group]['cache_file_name'] = $file_prefix.self::$_assets[$type][$group]['last_modified'].".".$type;

// Now minify/less if we choose so
// Now minify if we choose so
if ($type === 'css')
{
$output = self::$_assets[$type][$group]['combined'];

// Less
if (self::$enable_less and ! self::$freeze)
{
self::_init_less();
$output = self::$_less->parse($output);
}

// Minify CSS
if (self::$minify_css and ! self::$freeze)
{
Expand Down Expand Up @@ -1060,8 +1071,8 @@ private static function _init_cssmin()
if (self::$_enable_benchmark) self::$_ci->benchmark->mark("Assets::init_cssmin()_start");

// Load
if (defined('SPARKPATH')) include(reduce_double_slashes(SPARKPATH.'assets/'.ASSETS_VERSION.'/libraries/cssmin.php'));
else include(reduce_double_slashes(APPPATH.'/third_party/assets/cssmin.php'));
if (defined('SPARKPATH')) include(reduce_double_slashes(SPARKPATH.'assets/'.ASSETS_VERSION.'/libraries/cssmin/cssmin.php'));
else include(reduce_double_slashes(APPPATH.'/third_party/assets/cssmin/cssmin.php'));
self::$_cssmin_loaded = true;

// Set current dir for css min
Expand All @@ -1083,8 +1094,8 @@ private static function _init_jsmin()
if (self::$_enable_benchmark) self::$_ci->benchmark->mark("Assets::init_jsmin()_start");

// Load
if (defined('SPARKPATH')) include(reduce_double_slashes(SPARKPATH.'assets/'.ASSETS_VERSION.'/libraries/jsmin.php'));
else include(reduce_double_slashes(APPPATH.'/third_party/assets/jsmin.php'));
if (defined('SPARKPATH')) include(reduce_double_slashes(SPARKPATH.'assets/'.ASSETS_VERSION.'/libraries/jsmin/jsmin.php'));
else include(reduce_double_slashes(APPPATH.'/third_party/assets/jsmin/jsmin.php'));
self::$_jsmin_loaded = true;

// End benchmark
Expand All @@ -1103,8 +1114,8 @@ private static function _init_jspacker()
if (self::$_enable_benchmark) self::$_ci->benchmark->mark("Assets::init_jspacker()_start");

// Load
if (defined('SPARKPATH')) include(reduce_double_slashes(SPARKPATH.'assets/'.ASSETS_VERSION.'/libraries/jspacker.php'));
else include(reduce_double_slashes(APPPATH.'/third_party/assets/jspacker.php'));
if (defined('SPARKPATH')) include(reduce_double_slashes(SPARKPATH.'assets/'.ASSETS_VERSION.'/libraries/jspacker/jspacker.php'));
else include(reduce_double_slashes(APPPATH.'/third_party/assets/jspacker/jspacker.php'));
self::$_jspacker_loaded = true;

// End benchmark
Expand All @@ -1123,8 +1134,8 @@ private static function _init_less()
if (self::$_enable_benchmark) self::$_ci->benchmark->mark("Assets::init_less()_start");

// Load LessPHP
if (defined('SPARKPATH')) include(reduce_double_slashes(SPARKPATH.'assets/'.ASSETS_VERSION.'/libraries/lessc.php'));
else include(reduce_double_slashes(APPPATH.'/third_party/assets/lessc.php'));
if (defined('SPARKPATH')) include(reduce_double_slashes(SPARKPATH.'assets/'.ASSETS_VERSION.'/libraries/lessc/lessc.php'));
else include(reduce_double_slashes(APPPATH.'/third_party/assets/lessc/lessc.php'));

// Initialize
self::$_less = new lessc();
Expand All @@ -1137,6 +1148,39 @@ private static function _init_less()
}


/* ------------------------------------------------------------------------------------------ */

private static function _init_sass()
{
if ( ! self::$freeze and ! self::$_sass_loaded)
{
// Start benchmark
if (self::$_enable_benchmark) self::$_ci->benchmark->mark("Assets::init_sass()_start");

// Load PHPSass
if (defined('SPARKPATH')) include(reduce_double_slashes(SPARKPATH.'assets/'.ASSETS_VERSION.'/libraries/phpsass/SassParser.php'));
else include(reduce_double_slashes(APPPATH.'/third_party/assets/phpsass/SassParser.php'));

$options = array(
'style' => 'expanded',
'cache' => FALSE,
'syntax' => self::$base_url,
'debug' => FALSE,
'callbacks' => array(
'warn' => 'warn',
'debug' => 'debug'
),
);

// Initialize
self::$_sass = new SassParser( $options );

// End benchmark
if (self::$_enable_benchmark) self::$_ci->benchmark->mark("Assets::init_sass()_end");
}
}


/* ------------------------------------------------------------------------------------------ */

private static function _init_coffeescript()
Expand Down
Loading

0 comments on commit 243f863

Please sign in to comment.