Plack-Middleware-Assets

 view release on metacpan or  search on metacpan

README.pod  view on Meta::CPAN

    # concatenate sass files and transform them into css
    enable Assets => (
        files  => [<static/sass/*.sass>],
        type   => 'css',
        filter => sub { Text::Sass->new->sass2css(shift) },
        minify => 0
    );

    # pass a coderef for a custom minifier
    enable Assets => (
        files  => [<static/any/*.txt>],
        filter => sub {uc},
        minify => sub { s/ +/\t/g; $_ }
    );

    # concatenate any arbitrary content type
    enable Assets => (
        files => [<static/less/*.less>],
        type  => 'less'
    );

    $app;
  };



  
  # since this module ships only with the types css and js,
  # you have to implement the less type yourself:
  
  package Plack::Middleware::Assets::Type::less;
  use base 'Plack::Middleware::Assets::Type::css';
  use CSS::Minifier::XS qw(minify);
  use CSS::LESSp ();
  sub filter { CSS::LESSp->parse(@_) }

  # $env->{'psgix.assets'}->[0] points at the first asset.

=head1 DESCRIPTION

Plack::Middleware::Assets concatenates JavaScript and CSS files
and minifies them.

A C<md5> digest is generated and used as the unique url to the
asset.  For instance, if the first C<psgix.assets> is
C<static/js/*.js>, then the unique C<md5> url can be used in a
single HTML C<script> element for all js files.

The C<Last-Modified> header is set to the C<mtime> of the most
recently changed file.

The C<Expires> header is set to one month in advance. Set
L</expires> to change the time of expiry.

The concatented and minified content is cached in memory.

=head1 DEVELOPMENT MODE

 $ plackup app.psgi
 
 $ starman -E development app.psgi

In development mode the minification is disabled and the
concatenated content is regenerated if there were any changes
to the files.

=head1 CONFIGURATIONS

=over 4

=item separator

By default files are prepended with C</* filename */\n>
before being concatenated.

Set this to false to disable these comments.

If set to a string containing a C<%s>
it will be passed to C<sprintf> with the file name.

    separator => "# %s\n"

=item files

Files to concatenate.

=item filter

A coderef that can process/transform the content.

The current content will be passed in as C<$_[0]>
and also available via C<$_> for convenience.

This will be called before it is minified (if C<minify> is enabled).

=item minify

Value to indicate whether to minify or not. Defaults to C<1>.
This can also be a coderef which works the same as L</filter>.

=item type

Type of the asset.
Predefined types include C<css> and C<js>. Additional types can be implemented
by creating a new class in the C<Plack::Middleware::Assets::Type> namespace.
See the L</SYNOPSIS> for an example.

An attempt to guess the correct value is made from the file extensions
but this can be set explicitly if you are using non-standard file extensions.

=item expires

Time in seconds from now (i.e. C<time>) until the resource expires.

=item extension

File extension that is appended to the asset's URI.

=back

=head1 TODO



( run in 0.679 second using v1.01-cache-2.11-cpan-e93a5daba3e )