SYNOPSIS

# use the helper to create your Controller
script/myapp_create.pl controller Js Combine

# or:
script/myapp_create.pl controller Css Combine

# DONE. READY FOR USE.

# Just use it in your template:
# will deliver all JavaScript files concatenated (in Js-Controller)
<script type="text/javascript" src="/js/file1/file2/.../filex.js"></script>

# will deliver all CSS files concatenated (in Css-Controller)
<link rel="stylesheet" type="text/css" href="/css/file1/file2/.../filex.css" />


# in the generated controller you may add this to allow minification
# the trick behind is the existence of a sub named 'minify'
# inside your Controller.

use JavaScript::Minifier::XS qw(minify);
    # or:
use CSS::Minifier::XS qw(minify);

DESCRIPTION

Catalyst Controller that concatenates (and optionally minifies) static files like JavaScript or CSS into a single request. Depending on your configuration, files are also auto-added with a simple dependency-management.

The basic idea behind concatenation is that all files one Controller should handle reside in a common directory.

Assuming you have a directory with JavaScript files like:

root/static/js
 |
 +-- prototype.js
 |
 +-- helpers.js
 |
 +-- site.js

Then you could combine all files in a single tag (assuming your directory for the Controller is set to 'static/js' -- which is the default):

<script type="text/javascript" src="/js/prototype/helpers/site.js"></script>

If you add a dependency into your Controller's config like:

__PACKAGE__->config(
    ...
    depend => {
        helpers => 'prototype',
        site    => 'helpers',
    },
    ...
);

Now, the URI to retrieve the very same JavaScript files can be shortened:

<script type="text/javascript" src="/js/site.js"></script>

CONFIGURATION

A simple configuration of your Controller could look like this:

__PACKAGE__->config(
    # the directory to look for files
    # defaults to 'static/<<action_namespace>>'
    dir => 'static/js',

    # the (optional) file extension in the URL
    # defaults to action_namespace
    extension => 'js',

    # optional dependencies
    depend => {
        scriptaculous => 'prototype',
        builder       => 'scriptaculous',
        effects       => 'scriptaculous',
        dragdrop      => 'effects',
        slider        => 'scriptaculous',
        myscript      => [ qw(slider dragdrop) ],
    },

    # name of the minifying routine (defaults to 'minify')
    # will be used if present in the package
    minifier => 'minify',

    # should a HTTP expire header be set? This usually means, 
    # you have to change your filenames, if there a was change!
    expire => 1,

    # time offset (in seconds), in which the file will expire
    expire_in => 60 * 60 * 24 * 365 * 3, # 3 years

    # mimetype of response if wanted
    # will be guessed from extension if possible and not given
    # falls back to 'text/plain' if not guessable
    mimetype => 'application/javascript',
);

CONFIGURATION OPTIONS

TODO: writeme...

METHODS

BUILD

constructor for this Moose-driven class

AUTHOR

Wolfgang Kinkeldei, E<lt>wolfgang@kinkeldei.deE<gt>

LICENSE

This library is free software, you can redistribute it and/or modify it under the same terms as Perl itself.