line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mojolicious::Plugin::AssetPack::Pipe::HTML; |
2
|
1
|
|
|
1
|
|
8748
|
use Mojo::Base 'Mojolicious::Plugin::AssetPack::Pipe'; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
7
|
|
3
|
1
|
|
|
1
|
|
170
|
use Mojolicious::Plugin::AssetPack::Util qw(diag DEBUG); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
47
|
|
4
|
1
|
|
|
1
|
|
636
|
use HTML::Packer; |
|
1
|
|
|
|
|
7761
|
|
|
1
|
|
|
|
|
547
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
my $packer = HTML::Packer->init(); |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
has config => sub { my $self = shift; my $config = $self->assetpack->config || $self->assetpack->config({}); $config->{HTML} ||= {} }; |
9
|
|
|
|
|
|
|
has minify_opts => sub { {remove_comments => 1, remove_newlines => 0, no_compress_comment => 1, html5 => 1, %{shift->config->{minify_opts} ||= {}}, } };# do_javascript => 'clean', do_stylesheet => 'minify' , |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
sub process { |
12
|
2
|
|
|
2
|
1
|
5428
|
my ($self, $assets) = @_; |
13
|
2
|
|
|
|
|
10
|
my $store = $self->assetpack->store; |
14
|
|
|
|
|
|
|
|
15
|
2
|
50
|
|
|
|
20
|
return unless $self->assetpack->minify;# skip development |
16
|
|
|
|
|
|
|
|
17
|
2
|
|
|
|
|
21
|
my $content; |
18
|
|
|
|
|
|
|
return $assets->each( |
19
|
|
|
|
|
|
|
sub { |
20
|
4
|
|
|
4
|
|
906
|
my ($asset, $index) = @_; |
21
|
4
|
|
|
|
|
14
|
my $attrs = $asset->TO_JSON; |
22
|
4
|
|
|
|
|
136
|
$attrs->{key} = 'html-min'; |
23
|
4
|
|
|
|
|
6
|
$attrs->{minified} = 1; |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
#~ |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
return |
28
|
4
|
100
|
66
|
|
|
10
|
if $asset->format ne 'html' || $asset->minified; |
29
|
|
|
|
|
|
|
|
30
|
2
|
|
|
|
|
27
|
DEBUG && diag "Process HTML: [%s]", $asset->url;#$self->assetpack->app->dumper($asset) |
31
|
|
|
|
|
|
|
|
32
|
2
|
50
|
|
|
|
9
|
($content = $store->load($attrs)) && return $asset->content($content)->minified(1); |
33
|
2
|
50
|
|
|
|
45
|
length($content = $asset->content) || return; |
34
|
|
|
|
|
|
|
|
35
|
2
|
|
|
|
|
217
|
DEBUG && diag "Minify asset=[%s] with checksum=[%s] and minify_opts=[@{[ %{$self->minify_opts} ]}]", $asset->url, $asset->checksum, ; |
36
|
2
|
|
|
|
|
30
|
$packer->minify(\$content, $self->minify_opts); |
37
|
2
|
|
|
|
|
396179
|
$asset->content($store->save(\$content, $attrs))->minified(1); |
38
|
|
|
|
|
|
|
} |
39
|
2
|
|
|
|
|
12
|
); |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
1; |