weboap/carabiner

This package is abandoned and no longer maintained. No replacement package was suggested.

Inspired by CI Carabiner Asset Management by @tonydewan rebuilded for laravel 5

v3.0.4 2015-08-07 17:54 UTC

This package is not auto-updated.

Last update: 2017-05-13 00:13:32 UTC


README

Inspired by CI Carabiner Asset Management by @tonydewan rebuilded for Laravel.

For Laravel 4 users , use version v1.1.0

Installation

The recommended way to install Carabiner is through composer.

Step 1

Just add to composer.json file:

{
    "require": {
        "weboap/carabiner": "dev-master"
    }
}

then run

php composer.phar update

Step 2

Add

'Weboap\Carabiner\CarabinerServiceProvider'

to the list of service providers in app/config/app.php

Step 3

Run

php artisan vendor:publish

to publish carabiner config to

config/carabiner.php

then visit the config file that you just published to tune it.

Configuration

charset

default: UTF-8

appAssetsDirs array

web accessible folder where we can locate assets : css, js, less, scss

packageAssetsDirs array

package or not web accessible assets folders these assets will be copied and cached in web accessible cache folder.

version null|string

null | string Asset version / cache buster. disabled if null. Note: Global over all assets.

cache string

name of the cache folder, if not existant in the pubblic folder it will be created.

expires int

default : 1440 minutes Time to cache assets in minutes

prefix string

combined assets file prefix

group string

asset default group

groups array

Any groups defined here will automatically be included. Of course, they won't be displayed unless you explicity display them ( like this: Carabiner::display('jquery') )

Usage

to configure carabinier in runtime, use Carabiner::init();

as

$carabiner_config = array(
                    
                    'charset'                   => 'UTF-8', 
                    'appAssetsDirs'             => ['css', 'js'],
                    'packagesAssetsDirs'        => [
                                                    base_path() . '/resources/assets/css',
                                                    base_path() . '/resources/assets/js'
                                                    ],
                    'cache'                     => 'cache',
                    'expires'                   => 1440,
                    'version'                   => null,
                    'prefix'                    => 'output',
                    'group'                     => 'main'
                );
        
Carabiner::init($carabiner_config);


Add assets like so:

Asset Attributes :

combine         true|false
minify          true|false
cache           true|false
media           screen|print 
group           string default to 'main'

// add a js file
Carabiner::add('scripts.js');
    
// add a css file
Carabiner::add('reset.css');
    
// add a css file with a mediatype, combine and minify flags, 
Carabiner::add('path/relative/to/asset/dir/print.css',['combine' => true, 'minify'=> true, 'media' => 'print'] );
        




#### groups :

Carabiner::group( $group = 'main', array $assets, array $group_attributes = [ ], $override = false );

group attributes same as assets.
$override true|false to override assets attributes.


// Define JS
$js = [
        ['jquery.js', ['minify' => false, 'combine' => false ]],
        ['//maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js'],
        ['//ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js',['minify' => false, 'combine'=> true, 'cache' => true]],
        ['//code.angularjs.org/1.2.0-rc.3/angular.min.js.map',['minify' => false, 'combine'=> false, 'cache' => true]],
        ['//ajax.googleapis.com/ajax/libs/angularjs/1.2.0rc1/angular-route.min.js',['minify' => true, 'combine'=> true, 'cache' => true]],
        ['https://code.angularjs.org/1.2.12/angular-route.min.js.map',['minify' => false, 'combine'=> false, 'cache' => true]],
        ['app/account/app.js',['minify' => true, 'combine'=> true]], 
       
    ];

// create group
Carabiner::group('myjs', $js );



// Define CSS
$css = [
        ['//maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css', ['minify' => false, 'combine' => false, 'media'=> 'screen' ]],
        ['example-less.less', ['minify' => false, 'combine' => false ]], 
        ['example-scss.scss', ['minify' => false, 'combine' => false ]], 
        ['path/relative/to/asset/dir/print.css',['combine' => true, 'minify'=> true, 'media' => 'print']],
        ['app.css']
);

// create group
Carabiner::group('mycss', $css );

optionaly you can specify  assets attributes as ['minify' => false, 'combine' => false, 'cache' =>... ]
for your asset group and set the override to true

eg : Carabiner::group('mycss', $css, ['minify' => false, 'combine' => false, 'cache' =>... ], true); 

// you can assign an asset to a group individually 
// by passing the group name to the last parameter of the css/js functions

Carabiner::add('spec.css', ['group' => 'mygroup');


//To display a group, a specefic asset, or a type 
pass the name to the display function:

// display group in your template
Carabiner::display('myjs'); // group name defined as myjs
Carabiner::display('mycss'); // group name defined as mycss

or

Carabiner::display(); // to display all setup groups.


// Cache

the package clean the cache as part of its init function 
depending on the cache time ,
but if you need to clean the cache, you can use

Carabiner::emptyCache( $flag = 'all', $older = 0 );

$flag (string) : all | js | css | map
$older (int ):  older than in minutes. defaults to 0.


you can clear the cache as follow


if (app()->environment() == 'local')
{
        Carabiner::emptyCache("all");
}
else
{
        app('carabiner')->emptyCache('all', 1440);   
}


Enjoy!