Catalyst::Plugin::Assets integrates File::Assets into your Catalyst application. Essentially, it provides a unified way to include .css and .js assets from different parts of your program. When you're done processing a request, you can use $catalyst->assets->export() to generate HTML or $catalyst->assets->exports() to get a list of assets.

C::P::Assets will also handle .css files of different media types properly.

File::Assets is a tool for managing JavaScript and CSS assets in a (web) application. It allows you to "publish" assests in one place after having specified them in different parts of the application (e.g. throughout request and template processing phases).

You can configure C::P::Assets by manipulating the $catalyst->config->{'Plugin::Assets'} hash.

Note, in previous versions, the configuration location was $catalyst->config->{assets}

The following settings are available:

path # A path to automatically look for assets under (e.g. "/static" or "/assets")
# This path will be automatically prepended to includes, so that instead of
# doing ->include("/static/stylesheet.css") you can just do ->include("stylesheet.css")
output_path # The path to output the results of minification under (if any).
# For example, if output is "built/" (the trailing slash is important), then minified assets will be
# written to "root/<assets-path>/built/..."
minify # '1' to use JavaScript::Minifier and CSS::Minifier for minification
# 'yuicompressor:<path-to-yuicompressor-jar>' to use YUI Compressor
stash_var # The name of the key in the stash that provides the assets object (accessible via $catalyst->stash->{<stash_var}.
# By default, the <stash_var> is "assets".
# To disable the setting of the stash variable, set <stash_var> to undef

# Under the configuration below, the assets object will automatically
# look for assets (.css and .js files) under <home>/root/static/*
# If it needs to generate a minified asset, it will deposit the generated asset under <home>/root/static/built/*
# To turn off minification, set minify to 0
# Finally, the assets object is also available via $catalyst->stash->{assets} (This is actually the default setting)
__PACKAGE__->config(
name => 'Example',
'Plugin::Assets' => {
path => "/static",
output_path => "built/",
minify => 1,
stash_var => "assets", # This is the default setting
},
);
# Later, to include "http://localhost/static/example.css", do:
$catalyst->assets->include("example.css");
# To include "http://localhost/static/example.js", do:
$catalyst->assets->include("example.js");