File Coverage

blib/lib/Mojolicious/Plugin/AssetPack/Pipe/Css.pm
Criterion Covered Total %
statement 10 21 47.6
branch 1 6 16.6
condition 0 3 0.0
subroutine 3 4 75.0
pod 1 1 100.0
total 15 35 42.8


line stmt bran cond sub pod time code
1             package Mojolicious::Plugin::AssetPack::Pipe::Css;
2 7     7   44 use Mojo::Base 'Mojolicious::Plugin::AssetPack::Pipe';
  7         14  
  7         36  
3 7     7   1053 use Mojolicious::Plugin::AssetPack::Util qw(diag load_module DEBUG);
  7         17  
  7         1743  
4              
5             sub process {
6 7     7 1 15 my ($self, $assets) = @_;
7 7         38 my $store = $self->assetpack->store;
8 7         31 my $file;
9              
10 7 50       28 return unless $self->assetpack->minify;
11             return $assets->each(
12             sub {
13 0     0     my ($asset, $index) = @_;
14 0           my $attrs = $asset->TO_JSON;
15 0           $attrs->{key} = 'css-min';
16 0           $attrs->{minified} = 1;
17 0 0 0       return if $asset->format ne 'css' or $asset->minified;
18 0 0         return $asset->content($file)->minified(1) if $file = $store->load($attrs);
19 0           load_module 'CSS::Minifier::XS';
20 0           diag 'Minify "%s" with checksum %s.', $asset->url, $asset->checksum if DEBUG;
21 0           my $css = CSS::Minifier::XS::minify($asset->content);
22 0           $asset->content($store->save(\$css, $attrs))->minified(1);
23             }
24 0           );
25             }
26              
27             1;
28              
29             =encoding utf8
30              
31             =head1 NAME
32              
33             Mojolicious::Plugin::AssetPack::Pipe::Css - Minify CSS
34              
35             =head1 DESCRIPTION
36              
37             L will minify your "css" assets
38             if L is true and the asset is not
39             already minified.
40              
41             This module requires the optional module L to minify.
42              
43             =head1 METHODS
44              
45             =head2 process
46              
47             See L.
48              
49             =head1 SEE ALSO
50              
51             L.
52              
53             =cut