imt/yii-assetic

This extension integrates Assetic into Yii

Installs: 2 333

Dependents: 0

Suggesters: 0

Security: 0

Stars: 5

Watchers: 2

Forks: 2

Type:yii-extension

dev-master 2015-02-10 09:09 UTC

This package is not auto-updated.

Last update: 2024-11-05 02:53:35 UTC


README

Build Status Coverage Status Dependencies Status

IMTYiiAssetic

Overview

This extension integrates Assetic into Yii.

Note that this extension is under development. Use it at your own risk.

Installation

1. Using Composer (recommended)

To install IMTYiiAssetic with Composer just add the following to your composer.json file:

{
    "require": {
        "imt/yii-assetic": "dev-master"
    }
}

Do not forget to require the vendor/autoload.php file that is generated by Composer.

Then, you can install the new dependencies by running Composer's update command from the directory where your composer.json file is located:

$ php composer.phar update imt/yii-assetic

Now, Composer will automatically download all required files, and install them for you. All that is left to do is to update your main.php file, and register the new extension:

return array(
    // ...
    'aliases'    => array(
        // ...
        'IMT\YiiAssetic' => __DIR__ . '/../../vendor/imt/yii-assetic/src/',
        // ...
    ),
    // ...
    'components' => array(
        // ...
        'assetManager' => array(
            'class' => 'IMT\YiiAssetic\AssetManager',
            // ...
        ),
        'clientScript' => array(
            'class' => 'IMT\YiiAssetic\ClientScript',
            // ...
        ),
        // ...
    ),
    // ...
);

Usage

The main goal of this extension is to provide a rich set of Assetic filters to Yii. While developing this extension it was found that is not easy to integrate Assetic into Yii. Yii publishes a whole directory (not the specified files), and does not provide any mechanism to combine assets.

This extension overrides a few core Yii classes and provides some new properties to the overridden classes. Bellow you will find these properties and how use them.

AssetManager

Public properties

cache

Determines whether assets will be cached.

debug

Determines whether a debug mode will be enabled.

filtersByExt

A map that defines relations between file extensions and filters.

return array(
    // ...
    'components' => array(
        // ...
        'assetManager' => array(
            'class'        => 'IMT\YiiAssetic\AssetManager',
            'filtersByExt' => array(
                'css' => array('css_rewrite'),
                // more filters by ext
            ),
            // ...
        ),
        // ...
    ),
    // ...
);
userFilters

User-defined filters, can be used to override the core filters.

return array(
    // ...
    'components' => array(
        // ...
        'assetManager' => array(
            'class'   => 'IMT\YiiAssetic\AssetManager',
            'filters' => array(
                // built-in Assetic filters has already registered
                'css_rewrite' => 'Assetic\Filter\CssRewriteFilter',
                'smth'        => array(
                    'factoryClass' => 'IMT\YiiAssetic\SmthFilterFactory',
                    // some options that will be passed to the filter factory
                ),
                // more filters
            ),
            // ...
        ),
        // ...
    ),
    // ...
);
workers

An array of key-value pairs: the key is the alias, and the value is the class name.

return array(
    // ...
    'components' => array(
        'assetManager' => array(
            'class'   => 'IMT\YiiAssetic\AssetManager',
            'workers' => array(
                'smth' => 'IMY\YiiAssetic\SmthWorker',
                // more workers
            ),
            // ...
        ),
        // ...
    ),
    // ...
);

ClientScript

Each user-defined package has the new properties:

filtersByExt

A map that defines relations between file extensions and filters. If it is not specified, will be used the filtersByExt property that defined under the AssetManager.

combineTo

Determines whether assets will be combined into one asset. Actually it as a filename, the file extension should be omitted.

return array(
    // ...
    'components' => array(
        'clientScript' => array(
            'class'    => 'IMT\YiiAssetic\ClientScript',
            'packages' => array(
                'smth' => array(
                    'basePath'     => 'application.js.src.smth',
                    'css'          => array(
                        'css/file.css',
                        'css/file2.css',
                    ),
                    'filtersByExt' => array(
                        'css' => array('css_rewrite'),
                    ),
                    'combineTo'    => 'smth',
                ),
                // more packages
            ),
            // ...
        ),
        // ...
    ),
    // ...
);

Testing

$ make test

Contributing

Please see CONTRIBUTING for details.

Credits

License

This extension is released under the MIT license. See the complete license in the LICENSE file that is distributed with this source code.