This extension integrates Assetic into Yii.
Note that this extension is under development. Use it at your own risk.
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',
// ...
),
// ...
),
// ...
);
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.
Determines whether assets will be cached.
Determines whether a debug mode will be enabled.
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
),
// ...
),
// ...
),
// ...
);
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
),
// ...
),
// ...
),
// ...
);
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
),
// ...
),
// ...
),
// ...
);
Each user-defined package has the new properties:
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
.
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
),
// ...
),
// ...
),
// ...
);
$ make test
Please see CONTRIBUTING for details.
This extension is released under the MIT license. See the complete license in
the LICENSE
file that is distributed with this source code.