yii-assetic Extension that integrates Assetic into Yii

  1. Requirements
  2. Installation
  3. Usage
  4. Resources

This extension integrates Assetic into Yii.

Requirements

  • Yii 1.1 or above
  • Assetic 1.1 or above

Installation

1. Using Composer (recommended)

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

{
    // ...
    "require": {
        // ...
        "imt/yii-assetic": "*"
        // ...
    }
    // ...
}

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
            ),
            // ...
        ),
        // ...
    ),
    // ...
);

Resources

0 0
1 follower
0 downloads
Yii Version: Unknown
License: MIT
Category: Others
Developed by: Mr. T
Created on: Mar 12, 2014
Last updated: 10 years ago

Related Extensions