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.

SEE ALSO

Mojolicious::Plugin::AssetPack::Preprocessor, Mojolicious::Plugin::AssetPack::Preprocessor::Sass and Mojolicious::Plugin::AssetPack::Preprocessor::Scss.

METHODS

add

$self->add($extension => $object);

$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. These preprocessors will be chained. The callbacks will be called in the order they where added.

The default preprocessor defined is described under "detect".

In case of $object, the object need to be able to have the process() method.

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.

detect

Will add

Mojolicious::Plugin::AssetPack::Preprocessor::CoffeeScript, Mojolicious::Plugin::AssetPack::Preprocessor::Css, Mojolicious::Plugin::AssetPack::Preprocessor::JavaScript, Mojolicious::Plugin::AssetPack::Preprocessor::Jsx, Mojolicious::Plugin::AssetPack::Preprocessor::Less, Mojolicious::Plugin::AssetPack::Preprocessor::Sass and Mojolicious::Plugin::AssetPack::Preprocessor::Scss as preprocessors.

process

$self->process($extension => $assetpack, \$text, $filename);

Will run the preprocessor callbacks added by "add". The callbacks will be called with the $assetpack object as the first argument.

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