-
Notifications
You must be signed in to change notification settings - Fork 4
Filters
To process assets, Sprinkle uses filters. It has a simple enough interface to integrate your own filters.
Pretty much every filter uses third-party libraries to do the processing. For example, Sprinkle by default has cssmin filter which uses CssMin library (you'll find it in vendor/CssMin folder).
One of more distinctive filters is lessphp. It allows you to compile LESS files into pure CSS code.
You can apply filters to an asset like this:
less-stylesheet:
type: css
minify: true
combine: true
src: public/test.less
filters: [lessphp]
or define it manually in your controller:
$this->sprinkle->css('public/test.less', 'screen', FALSE, FALSE, array('lessphp'));
When you apply filters to assets, they are then cached and used for output.
If you want to use a filter to minify css/js assets, you don't need to specify the filter manually. By setting minify to TRUE you tell Sprinkle to use the default filter for minifying css or js assets.
To create your own filter, create a file in the filters directory and extend the Sprinkle_Filter class.
class my_filter extends Sprinkle_Filter { }
Keep in mind that the class name needs to be the same as the file name of the class. The only method you should really care about is output(\Sprinkle\Asset $asset). The method should return the path to the temporary (processed) file. Usually _save_file() method will take care of that. To learn more, study the existing filters.