File Coverage

blib/lib/Mojolicious/Plugin/AssetPack/Pipe/Css.pm
Criterion Covered Total %
statement 21 21 100.0
branch 5 6 83.3
condition 1 3 33.3
subroutine 4 4 100.0
pod 1 1 100.0
total 32 35 91.4


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