Dancer::Plugin::Assets - Manage and minify .css and .js assets in a Dancer application
use Dancer::Plugin::Assets qw( assets add_asset );
get "/index" => sub { ## Include assets by plugin method add_asset "/css/beautiful.css"; add_asset "/css/handlebars.js"; ## Include assets by assets object assets->include( "/css/main.css" ); assets->include( "/js/something.js" ); };
<html> <head><title>[% title %]</title> [% css_tags %] </head> <body> </body> [% js_tags %] </html>
<html> <head><title>[% title %]</title> [% add_asset("/js/jquery.js") %] [% add_asset("/js/handlebars.js") %] [% add_asset("/css/beautiful.css") %] [% CALL assets.include("/js/foo.js") %] [% css_and_js_tags || js_and_css_tags %] </head> <body> </body> </html>
Dancer::Plugin::Assets integrates File::Assets into your Dancer 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 assets->export() or [% css_and_js_tags %] to generate HTML or assets->exports() to get a list of assets.
D::P::Assets will also handle .css files of different media types properly.
In addition, D::P::Assets includes support for minification via YUI compressor, JavaScript::Minifier, CSS::Minifier, JavaScript::Minifier::XS, and CSS::Minifier::XS
Note that Dancer::Plugin::Assets does not serve files directly, it will work with Static::Simple or whatever static-file-serving mechanism you're using.
For usage hints and tips, see File::Assets
You can configure D::P::Assets by manipulating the environment configration files, e.g.
config.yml environments/development.yml environments/production.yml
The following settings are available:
url # The url to access the asset files default "/" base_dir # A path to automatically look for assets under (e.g. "/public") # This path will be automatically prepended to includes, so that instead of # doing ->include("/public/css/stylesheet.css") you can just do ->include("/css/stylesheet.css") output_dir # 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>/static/..." # # Designates the output path for minified .css and .js assets # The default output path pattern is "%n%-l%-d.%e" (rooted at the dir of <base>) minify # "1" or "best" - Will either use JavaScript::Minifier::XS> & CSS::Minifier::XS or # JavaScript::Minifier> & CSS::Minifier (depending on availability) # for minification # "0" or "" or undef - Don't do any minfication (this is the default) # "./path/to/yuicompressor.jar" - Will use YUI Compressor via the given .jar for minification # "minifier" - Will use JavaScript::Minifier & CSS::Minifier for minification minified_name # The name of the key in the stash that provides the assets object (accessible via config->{plugins}{assets}{minified_name}. # By default, the <minified_name> is "minified".
Here is an example configuration: ( All the value are set by default )
plugins: Assets: base_dir: "/public" output_dir: "static/%n%-l.%e" minified_name: "minified" minify: 1
Return File::Assets object that exists throughout the lifetime of the request
same as sub { assets->include( shift ); return undef }
same as [% CALL assets.include( "file..." ) %]
return tags of css in html
return tags of javascript in html
return tags in this order of css and javascript in html
return tags in this order of javascript and css in html
Michael Vu, <micvu at cpan.org>
<micvu at cpan.org>
Please report any bugs or feature requests to bug-dancer-plugin-assets at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Dancer::Plugin::Assets. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
bug-dancer-plugin-assets at rt.cpan.org
You can find documentation for this module with the perldoc command.
perldoc Dancer::Plugin::Assets
You can also look for information at:
RT: CPAN's request tracker
http://rt.cpan.org/NoAuth/Bugs.html?Dist=Dancer-Plugin-Assets
AnnoCPAN: Annotated CPAN documentation
http://annocpan.org/dist/Dancer-Plugin-Assets
CPAN Ratings
http://cpanratings.perl.org/d/Dancer-Plugin-Assets
Search CPAN
http://search.cpan.org/dist/Dancer-Plugin-Assets
GIT Respority
https://bitbucket.org/mvu8912/p5-dancer-plugin-assets
File::Assets
Dancer::Plugin
http://developer.yahoo.com/yui/compressor/
JavaScript::Minifier::XS
CSS::Minifier::XS
JavaScript::Minifier
CSS::Minifier
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
To install Dancer::Plugin::Assets, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Dancer::Plugin::Assets
CPAN shell
perl -MCPAN -e shell install Dancer::Plugin::Assets
For more information on module installation, please visit the detailed CPAN module installation guide.