line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
3
|
|
|
3
|
|
901828
|
use strictures; |
|
3
|
|
|
|
|
3589
|
|
|
3
|
|
|
|
|
13
|
|
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
package Dancer2::Plugin::Minify; |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
# ABSTRACT: Minify HTML, JavaScript and CSS |
6
|
|
|
|
|
|
|
|
7
|
3
|
|
|
3
|
|
1694
|
use Dancer2::Plugin; |
|
3
|
|
|
|
|
4924
|
|
|
3
|
|
|
|
|
14
|
|
8
|
|
|
|
|
|
|
|
9
|
3
|
|
|
3
|
|
4987
|
use HTML::Packer; |
|
3
|
|
|
|
|
13987
|
|
|
3
|
|
|
|
|
69
|
|
10
|
3
|
|
|
3
|
|
1465
|
use JavaScript::Packer; |
|
3
|
|
|
|
|
12155
|
|
|
3
|
|
|
|
|
80
|
|
11
|
3
|
|
|
3
|
|
1247
|
use CSS::Packer; |
|
3
|
|
|
|
|
5614
|
|
|
3
|
|
|
|
|
81
|
|
12
|
3
|
|
|
3
|
|
15
|
use Moo::Role; |
|
3
|
|
|
|
|
3
|
|
|
3
|
|
|
|
|
18
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
our $VERSION = '0.001'; # VERSION |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
has html => ( |
17
|
|
|
|
|
|
|
is => 'lazy', |
18
|
1
|
|
|
1
|
|
298
|
builder => sub { HTML::Packer->init }, |
19
|
|
|
|
|
|
|
); |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
has js => ( |
22
|
|
|
|
|
|
|
is => 'lazy', |
23
|
1
|
|
|
1
|
|
311
|
builder => sub { JavaScript::Packer->init }, |
24
|
|
|
|
|
|
|
); |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
has css => ( |
27
|
|
|
|
|
|
|
is => 'lazy', |
28
|
1
|
|
|
1
|
|
320
|
builder => sub { CSS::Packer->init }, |
29
|
|
|
|
|
|
|
); |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
register minify => sub { |
32
|
3
|
|
|
3
|
|
1220470
|
my ( $dsl, $what, $text, $args ) = @_; |
33
|
3
|
50
|
|
|
|
12
|
return unless defined $text; |
34
|
3
|
|
50
|
|
|
56
|
$args //= {}; |
35
|
3
|
100
|
|
|
|
16
|
return $dsl->_minify_js( $text, $args ) if $what eq 'js'; |
36
|
2
|
100
|
|
|
|
9
|
return $dsl->_minify_css( $text, $args ) if $what eq 'css'; |
37
|
1
|
50
|
|
|
|
7
|
return $dsl->_minify_html( $text, $args ) if $what eq 'html'; |
38
|
0
|
|
|
|
|
0
|
$dsl->error("unknown engine: $what"); |
39
|
|
|
|
|
|
|
}, |
40
|
|
|
|
|
|
|
{ is_global => 1 }; |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub _minify_html { |
43
|
1
|
|
|
1
|
|
2
|
my ( $dsl, $html, $args ) = @_; |
44
|
1
|
|
|
|
|
3
|
my $cfg = plugin_setting; |
45
|
|
|
|
|
|
|
my $remove_comments = $cfg->{remove_comments} // $args->{remove_comments} |
46
|
1
|
|
33
|
|
|
114
|
// 1; |
|
|
|
50
|
|
|
|
|
47
|
|
|
|
|
|
|
my $remove_newlines = $cfg->{remove_newlines} // $args->{remove_newlines} |
48
|
1
|
|
33
|
|
|
5
|
// 1; |
|
|
|
50
|
|
|
|
|
49
|
1
|
|
33
|
|
|
16
|
my $js_compress = $cfg->{js_compress} // $args->{js_compress} // 'best'; |
|
|
|
50
|
|
|
|
|
50
|
|
|
|
|
|
|
my $css_compress = $cfg->{css_compress} // $args->{css_compress} |
51
|
1
|
|
33
|
|
|
5
|
// 'minify'; |
|
|
|
50
|
|
|
|
|
52
|
1
|
|
33
|
|
|
5
|
my $html5 = $cfg->{html5} // $args->{html5} // 1; |
|
|
|
50
|
|
|
|
|
53
|
1
|
|
|
|
|
5
|
$dsl->html->minify( |
54
|
|
|
|
|
|
|
\$html, |
55
|
|
|
|
|
|
|
{ |
56
|
|
|
|
|
|
|
remove_comments => $remove_comments, |
57
|
|
|
|
|
|
|
remove_newlines => $remove_newlines, |
58
|
|
|
|
|
|
|
do_javascript => $js_compress, |
59
|
|
|
|
|
|
|
do_stylesheet => $css_compress, |
60
|
|
|
|
|
|
|
html5 => 1, |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
); |
63
|
1
|
|
|
|
|
6940
|
return $html; |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub _minify_js { |
67
|
1
|
|
|
1
|
|
2
|
my ( $dsl, $js, $args ) = @_; |
68
|
1
|
|
|
|
|
5
|
my $cfg = plugin_setting; |
69
|
1
|
|
33
|
|
|
134
|
my $comress = $cfg->{js_compress} // $args->{compress} // 'best'; |
|
|
|
50
|
|
|
|
|
70
|
1
|
|
|
|
|
6
|
$dsl->js->minify( |
71
|
|
|
|
|
|
|
\$js, |
72
|
|
|
|
|
|
|
{ |
73
|
|
|
|
|
|
|
compress => $comress, |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
); |
76
|
1
|
|
|
|
|
4982
|
return $js; |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
sub _minify_css { |
80
|
1
|
|
|
1
|
|
11
|
my ( $dsl, $css, $args ) = @_; |
81
|
1
|
|
|
|
|
4
|
my $cfg = plugin_setting; |
82
|
1
|
|
33
|
|
|
184
|
my $comress = $cfg->{css_compress} // $args->{compress} // 'minify'; |
|
|
|
50
|
|
|
|
|
83
|
1
|
|
|
|
|
5
|
$dsl->css->minify( |
84
|
|
|
|
|
|
|
\$css, |
85
|
|
|
|
|
|
|
{ |
86
|
|
|
|
|
|
|
compress => $comress, |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
); |
89
|
1
|
|
|
|
|
2031
|
return $css; |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
register_plugin; |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
1; |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
__END__ |