Plack-Middleware-Assets-RailsLike

 view release on metacpan or  search on metacpan

README.md  view on Meta::CPAN

# NAME

Plack::Middleware::Assets::RailsLike - Bundle and minify JavaScript and CSS files

# SYNOPSIS

    use strict;
    use warnings;
    use MyApp;
    use Plack::Builder;

    my $app = MyApp->new->to_app;
    builder {
        enable 'Assets::RailsLike', root => './htdocs';
        $app;
    };

# WARNING

__This module is under development and considered BETA quality.__

# DESCRIPTION

Plack::Middleware::Assets::RailsLike is a middleware to bundle and minify
JavaScript and CSS (included Sass and LESS) files like Ruby on Rails Asset
Pipeline.

At first, you create a manifest file. The Manifest file is a list of JavaScript
and CSS files you want to bundle. You can also use Sass and LESS as css files.
The Manifest syntax is same as Rails Asset Pipeline, but only support
`require` command.

    > vim ./htdocs/assets/main-page.js
    > cat ./htdocs/assets/main-page.js
    //= require jquery
    //= require myapp



Next, write URLs of manifest file to your html. This middleware supports
versioning. So you can add version string in between its file basename and
suffix.

    <- $basename-$version.$suffix ->
    <script type="text/javascript" src="/assets/main-page-v2013060701.js">

If manifest files were requested, bundle files in manifest file and serve it or
serve bundled data from cache. In this case, find jquery.js and myapp.js from
search path (default search path is `$root`/assets). This middleware return
HTTP response with `Cache-Control`, `Expires` and `Etag`. `Cache-Control`
and `Expires` are computed from the `expires` option. `Etag` is computed
from bundled content.

# CONFIGURATIONS

- root

    Document root to find manifest files to serve.

    Default value is current directory('.').

- path

    The URL pattern (regular expression) for matching.

    Default value is `qr{^/assets}`.

- search\_path

    Paths to find javascript and css files.

    Default value is `[qw($root/assets)]`.

- minify

    Minify javascript and css files if true.

    Default value is `1`.

- cache

    Store concatenated data in memory by default using [Cache::MemoryCache](http://search.cpan.org/perldoc?Cache::MemoryCache). The
    `cache` option must be a object implemented `get` and `set` methods. For
    example, [Cache::Memcached::Fast](http://search.cpan.org/perldoc?Cache::Memcached::Fast). If `$ENV{PLACK_ENV} eq "development"` and
    you didn't pass a cache object, cache is disabled.

    Default is a [Cache::MemoryCache](http://search.cpan.org/perldoc?Cache::MemoryCache) Object.

        Cache::MemoryCache->new({
            namespace           => "Plack::Middleware::Assets::RailsLike",
            default_expires_in  => $expires
            auto_purge_interval => '1 day',
            auto_purge_on_set   => 1,
            auto_purge_on_get   => 1
        })



( run in 0.676 second using v1.01-cache-2.11-cpan-524268b4103 )