NAME

Web::AssetLib::Library - a base class for writing your own asset library, and configuring the various pipeline plugins

SYNOPSIS

Create a library for your project:

package My::Library;

use Moose;

extends 'Web::AssetLib::Library';

sub jQuery{
    return Web::AssetLib::Asset->new(
        type         => 'javascript',
        input_engine => 'LocalFile',
        rank         => -100,
        input_args => { path => "your/local/path/jquery.min.js", }
    );
}

1;

Instantiate your library

use My::Library;

# configure at least one input and one output plugin
# (and optionally, a minifier plugin)
my $lib = My::Library->new(
    input_engines => [
        Web::AssetLib::InputEngine::LocalFile->new(
            search_paths => ['/my/assets/root/']
        )
    ],
    output_engines => [
        Web::AssetLib::OutputEngine::LocalFile->new(
            output_path => '/my/webserver/path/assets/'
        )
    ]
);

# create an asset bundle to represent a group of assets
# that should be compiled together:

my $homepage_javascript = Web::AssetLib::Bundle->new();
$hompage_javascript->addAsset($lib->jQuery);


# compile your bundle
my $html_tag = $lib->compile( bundle => $homepage_javascript )->as_html;

DESCRIPTION

Web::AssetLib::Library holds the instances of the plugins you wish to use. It is also suggested that this class be subclassed and used as a place to manage availalbe assets.

ATTRIBUTES

input_engines

Arrayref of Web::AssetLib::InputEngine instance(s) that you wish to use with your library

minifier_engines

Arrayref of Web::AssetLib::MinifierEngine instance(s) that you wish to use with your library

output_engines

Arrayref of Web::AssetLib::OutputEngine instance(s) that you wish to use with your library

METHODS

compile( :$bundle, :$asset, :$output_engine = 'LocalFile', :$minifier_engine = 'Standard' )

$library->compile( bundle => $bundle )
$library->compile( asset => $asset )

# specify desired output and/or minifier engine:
$library->compile( ..., output_engine => 'String', minifier_engine => 'CustomMinifier' );

# skip minification
$library->compile( bundle => $bundle, minifier_engine => undef )

print $bundle->as_html();
print $library->compile( bundle => $bundle )->as_html()
# <script src="/your/output.js" type="text/javascript"></script>

Combines and processes a bundle or asset, sending it through the provided minifer, and provided output engine. Provide a type to selectively filter to only a single file type.

parameters

One of:

Optionally:

  • output_engine — string; partial class name that will match one of the provided output_engines for your library (defaults to "LocalFile")

  • minifier_engine — string; partial class name that will match one of the provided minifer_engines for your library. Set to undef if no minification is desired. (defaults to "Standard")

  • type — string; filter compilation by file type (will output only assets of this type). The following types are supported: js, javascript, css, stylesheet.

  • html_attrs — hashref; attributes to be included in output html

AUTHOR

Ryan Lang <rlang@cpan.org>