bmidget / kohana-assets
Handy library for serving up pre-compiled js and css/less files
Installs: 5 267
Dependents: 0
Suggesters: 0
Security: 0
Stars: 4
Watchers: 5
Forks: 2
Open Issues: 1
Type:kohana-module
Requires
- php: >=5.3.3
- composer/installers: ~1.0
- kohana/core: >=3.3
- oyejorge/less.php: >=1.7
This package is not auto-updated.
Last update: 2024-12-17 06:45:28 UTC
README
Create an assets object
$assets = Assets::factory();
Define hashgroups in config files. Here are some examples:
// config/js.php
$base = [
'bs' => DOCROOT.'assets/bootstrap/dist/js/bootstrap.min.js',
'site' => DOCROOT.'assets/js/site.js',
];
return [
'default' => $base,
'admin' => $base + [
'footable' => DOCROOT.'assets/footable/js/footable.js',
'footable-paginate' => DOCROOT.'assets/footable/js/footable.paginate.js',
'footable-filter' => DOCROOT.'assets/footable/js/footable.filter.js',
'footable-sort' => DOCROOT.'assets/footable/js/footable.sort.js',
'admin' => DOCROOT.'assets/js/admin.js',
]
];
// config/css.php
return [
'default' = [
'site' => DOCROOT.'assets/less/site.less',
],
'public' => [
'site' => DOCROOT.'assets/less/site.less',
'public' => DOCROOT.'assets/less/public.less',
],
'admin' => [
'site' => DOCROOT.'assets/less/site.less',
'footable' => DOCROOT.'assets/less/footable.less',
'admin' => DOCROOT.'assets/less/admin.less',
],
'special_page' => [
'site' => DOCROOT.'assets/less/site.less',
'special' => DOCROOT.'assets/less/special.less',
],
];
Pre-compile assets
You can create a minion task to do this as a deployment script for your production environment.
class Task_Asset_Compile extends Minion_Task {
protected function _execute( array $params)
{
$asset = Assets::factory();
$asset->update_config();
}
}
And in your dev environment, it's nice to update the compiled assets every refresh. Here's an example of setting this up in a Template controller:
$this->template->bind('assets', $this->_assets);
$this->_assets = Assets::factory();
if (Kohana::$environment === Kohana::DEVELOPMENT)
{
$this->_assets->update_config();
}
And in your view template, return the script tags pointing to the proper compiled js and css files
<?=$assets->get_cached('css', true)?>
<?=$assets->get_cached('js', true)?>