NAME
Mojolicious::Plugin::AssetPack::Preprocessors - Holds preprocessors for the assetpack
DESCRIPTION
Mojolicious::Plugin::AssetPack::Preprocessors is used to hold a list of preprocessors for a given file type.
Bundled preprocessors
Mojolicious::Plugin::AssetPack will load the preprocessors in the list below, when you try to handle a given file.
NOTE! Some of the preprocessors require optional dependencies to function properly.
Mojolicious::Plugin::AssetPack::Preprocessor::CoffeeScript
Handle
.coffee
files.Mojolicious::Plugin::AssetPack::Preprocessor::Css
Handle
.css
files.Mojolicious::Plugin::AssetPack::Preprocessor::JavaScript
Handle
.js
files.Mojolicious::Plugin::AssetPack::Preprocessor::Jsx
Handle
.jsx
files.Mojolicious::Plugin::AssetPack::Preprocessor::Less
Handle
.less
files.Mojolicious::Plugin::AssetPack::Preprocessor::Sass
Handle
.sass
files.Mojolicious::Plugin::AssetPack::Preprocessor::Scss
Handle
.scss
files.
Custom preprocessors
You can also define your own preprocessors. Example code:
package My::Preprocessor;
use Mojo::Base 'Mojolicious::Plugin::AssetPack::Preprocessor';
sub process {
my ($self, $assetpack, $text, $path) = @_;
$$text = "// yikes!\n" if 5 < rand 10;
}
app->asset->preprocessors->add(js => 'My::Preprocessor' => {});
ATTRIBUTES
fallback
TODO
METHODS
add
$self->add($extension => $object);
$self->add($extension => $class => \%attrs);
$self->add($extension => sub {
my ($assetpack, $text, $file) = @_;
$$text =~ s/foo/bar/ if $file =~ /baz/ and $assetpack->minify;
});
Define a preprocessor which is run on a given file extension. All the preprocessors will be called in the order they are added.
In case of $object
, the object need to be able to have the process()
method.
These two are the same:
use Mojolicious::Plugin::AssetPack::Preprocessor::Scss;
my $object = Mojolicious::Plugin::AssetPack::Preprocessor::Scss->new(\%attrs);
$self->add(scss => $object);
# the above is the same as... (no need to load the package)
$self->add(scss => Scss => \%attrs);
A $class
without "::" will be prefixed with Mojolicious::Plugin::AssetPack::Preprocessor::
.
can_process
$bool = $self->can_process($extension);
Returns true if there is at least one of the preprocessors added can handle this extensions.
This means that a preprocessor object can be added, but is unable to actually process the asset. This is a helper method, which can be handy in unit tests to check if "sass", "jsx" or other preprocessors are actually installed.
checksum
$str = $self->checksum($extension => \$text, $filename);
Calls the checksum()
method in all the preprocessors for the $extension
and returns a combined checksum.
process
$self->process($extension => $assetpack, \$text, $filename);
Will run the preprocessors added by "add".
map_type
DEPRECATED: The mapping is already done based on input files.
remove
$self->remove($extension);
$self->remove($extension => $cb);
This method will remove all preprocessors defined for an extension, or just a given $cb
.
AUTHOR
Jan Henning Thorsen - jhthorsen@cpan.org