Hello CodeIgniter Community,
this will be my first submission for CI - don’t expect too much ![]()
This Library gives you the chance to add assets to your project and output them in a joined (optionally compressed) file. This works for css (csstidy 1.3) and jsmin (jsmin-1.1.1).
Get the Library here:
v0.1: AssetLib
Here is a little example:
Controller:
$this->load->library('assetlib');
$config['enable_csstidy'] = TRUE;
$config['enable_jsmin'] = TRUE;
$config['csstidy_config'] = array(
'remove_bslash' => TRUE,
'compress_colors' => TRUE,
'compress_font-weight' => TRUE,
'lowercase_s' => FALSE,
'optimise_shorthands' => 1,
'remove_last_,' => TRUE,
'case_properties' => 1,
'sort_properties' => FALSE,
'sort_selectors' => FALSE,
'merge_selectors' => 2,
'discard_invalid_properties' => FALSE,
'css_level' => 'CSS2.1',
'preserve_css' => FALSE,
'timestamp' => FALSE,
);
$config['csstidy_template'] = "high_compression";
$this->assetlib->initialize($config);
$this->assetlib->add("/style/default.css" );
$this->assetlib->add("/style/default_cs.css" );
$this->assetlib->add("/assets/astrumnex.js" );
In the $config[‘csstidy_config] variable you can use any config variable from csstidy to compress the code in your way.
View:
<?=$this->assetlib->output('all'); ?>
or
<?=$this->assetlib->output('css'); ?>
or
<?=$this->assetlib->output('js'); ?>
results:
<link rel="stylesheet" href="/assets/base.css" type="text/css" media="screen" />
Installation:
Step #1: You need to add some lines to your config.php file:
/*
|--------------------------------------------------------------------------
| Asset storage
|--------------------------------------------------------------------------
|
| The path to where to storage the joined assets. The assetlib will store
| as "base.css" and "base.js". (relative from CI index.php)
|
| asset_storage = "/assets" (as example)
|
*/
$config['asset_storage'] = "/assets/";
$config['asset_cache'] = TRUE;
$config['asset_expiration'] = 7200;
/*
|--------------------------------------------------------------------------
| CSSTidy Config
|--------------------------------------------------------------------------
|
| The path from your site's root in which the csstidy folder is. Note
| this is from the site's root, not the file system root. Also note the
| required slashes at start and finish.
|
| csstidy_basepath = "/system/plugins/csstidy" (as example)
|
*/
$config['csstidy_basepath'] = "/plugins/csstidy/";
/*
|--------------------------------------------------------------------------
| JSmin Config
|--------------------------------------------------------------------------
|
| Enter the path to your jsmin.php file. (relative from BASEPATH)
|
| jsmin = "/system/plugins/jsmin1.1.1.php" (as example)
|
*/
$config['jsmin'] = "/plugins/jsmin-1.1.1.php";
Step #2:
Paste “assetlib.php” in your /system/application/libraries folder.
Step #3 (optionally):
Download csstidy
and put the contents of the package into your /system/plugins folder (or wherever you’ve set it in your config file)
Download jsmin
and put the jsmin-1.1.1.php into your /system/plugins folder (or wherever you’ve set it in your config file)
Please give me some feedback
