Mojolicious::Plugin::AssetPack::Preprocessors - Holds preprocessors for the assetpack
Mojolicious::Plugin::AssetPack::Preprocessors is used to hold a list of preprocessors for a given file type.
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.
.coffee
Mojolicious::Plugin::AssetPack::Preprocessor::Css
Handle .css files.
.css
Mojolicious::Plugin::AssetPack::Preprocessor::JavaScript
Handle .js files.
.js
Mojolicious::Plugin::AssetPack::Preprocessor::Jsx
Handle .jsx files.
.jsx
Mojolicious::Plugin::AssetPack::Preprocessor::Less
Handle .less files.
.less
Mojolicious::Plugin::AssetPack::Preprocessor::Sass
Handle .sass files.
.sass
Mojolicious::Plugin::AssetPack::Preprocessor::Scss
Handle .scss files.
.scss
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' => {});
TODO
$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.
$object
process()
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::.
$class
Mojolicious::Plugin::AssetPack::Preprocessor::
$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.
$str = $self->checksum($extension => \$text, $filename);
Calls the checksum() method in all the preprocessors for the $extension and returns a combined checksum.
checksum()
$extension
$self->process($extension => $assetpack, \$text, $filename);
Will run the preprocessors added by "add".
DEPRECATED: The mapping is already done based on input files.
$self->remove($extension); $self->remove($extension => $cb);
This method will remove all preprocessors defined for an extension, or just a given $cb.
$cb
Jan Henning Thorsen - jhthorsen@cpan.org
jhthorsen@cpan.org
To install Mojolicious::Plugin::AssetPack, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Mojolicious::Plugin::AssetPack
CPAN shell
perl -MCPAN -e shell install Mojolicious::Plugin::AssetPack
For more information on module installation, please visit the detailed CPAN module installation guide.