line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mojolicious::Plugin::CSSLoader; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# ABSTRACT: move css loading to the end of the document |
4
|
|
|
|
|
|
|
|
5
|
14
|
|
|
14
|
|
9797
|
use strict; |
|
14
|
|
|
|
|
30
|
|
|
14
|
|
|
|
|
433
|
|
6
|
14
|
|
|
14
|
|
65
|
use warnings; |
|
14
|
|
|
|
|
33
|
|
|
14
|
|
|
|
|
365
|
|
7
|
|
|
|
|
|
|
|
8
|
14
|
|
|
14
|
|
67
|
use parent 'Mojolicious::Plugin'; |
|
14
|
|
|
|
|
21
|
|
|
14
|
|
|
|
|
83
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our $VERSION = '0.08'; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub register { |
13
|
14
|
|
|
14
|
1
|
9280
|
my ($self, $app, $config) = @_; |
14
|
|
|
|
|
|
|
|
15
|
14
|
|
100
|
|
|
82
|
my $base = $config->{base} || ''; |
16
|
14
|
|
100
|
|
|
70
|
my $media = $config->{media} || ''; |
17
|
|
|
|
|
|
|
|
18
|
14
|
100
|
100
|
|
|
59
|
if ( $base and substr( $base, -1 ) ne '/' ) { |
19
|
4
|
|
|
|
|
10
|
$base .= '/'; |
20
|
|
|
|
|
|
|
} |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
$app->helper( css_load => sub { |
23
|
43
|
|
|
43
|
|
351398
|
my $c = shift; |
24
|
|
|
|
|
|
|
|
25
|
43
|
100
|
|
|
|
165
|
if ( $_[1]->{check} ) { |
26
|
|
|
|
|
|
|
my $asset = $c->app->static->file( |
27
|
8
|
100
|
|
|
|
25
|
$_[1]->{no_base} ? $_[0] : "$base$_[0]" |
28
|
|
|
|
|
|
|
); |
29
|
|
|
|
|
|
|
|
30
|
8
|
100
|
|
|
|
1012
|
return '' if !$asset; |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
40
|
|
|
|
|
96
|
push @{ $c->stash->{__CSSLOADERFILES__} }, [ @_ ]; |
|
40
|
|
|
|
|
124
|
|
34
|
14
|
|
|
|
|
128
|
} ); |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
$app->hook( after_render => sub { |
37
|
32
|
|
|
32
|
|
30081
|
my ($c, $content, $format) = @_; |
38
|
|
|
|
|
|
|
|
39
|
32
|
100
|
|
|
|
123
|
return if $format ne 'html'; |
40
|
31
|
100
|
|
|
|
95
|
return if !$c->stash->{__CSSLOADERFILES__}; |
41
|
30
|
100
|
|
|
|
329
|
return if 'ARRAY' ne ref $c->stash->{__CSSLOADERFILES__}; |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
my $load_css = |
44
|
|
|
|
|
|
|
join "\n", |
45
|
|
|
|
|
|
|
map{ |
46
|
40
|
|
|
|
|
215
|
my ($file,$config) = @{ $_ }; |
|
40
|
|
|
|
|
95
|
|
47
|
40
|
|
100
|
|
|
99
|
$file //= ''; |
48
|
|
|
|
|
|
|
|
49
|
40
|
100
|
|
|
|
111
|
my $local_base = $config->{no_base} ? '' : $base; |
50
|
|
|
|
|
|
|
|
51
|
40
|
100
|
|
|
|
106
|
$local_base = $c->url_for( $local_base ) if $local_base; |
52
|
|
|
|
|
|
|
|
53
|
40
|
|
|
|
|
2958
|
my $local_media = ""; |
54
|
|
|
|
|
|
|
|
55
|
40
|
100
|
|
|
|
103
|
$local_media = ' media="' . $media . '"' if $media; |
56
|
40
|
100
|
|
|
|
149
|
$local_media = ' media="' . $config->{media} . '"' if $config->{media}; |
57
|
|
|
|
|
|
|
|
58
|
40
|
|
|
|
|
105
|
my $ie_start = ''; |
59
|
40
|
|
|
|
|
105
|
my $ie_end = ''; |
60
|
|
|
|
|
|
|
|
61
|
40
|
100
|
|
|
|
188
|
if ( exists $config->{ie} ) { |
62
|
7
|
|
|
|
|
10
|
my $start_extra = ''; |
63
|
7
|
|
|
|
|
8
|
my $end_extra = ''; |
64
|
7
|
|
|
|
|
8
|
my $cmp = ''; |
65
|
7
|
|
|
|
|
10
|
my $version = ''; |
66
|
|
|
|
|
|
|
|
67
|
7
|
100
|
100
|
|
|
36
|
if ( !ref $config->{ie} && !$config->{ie} ) { |
|
|
100
|
|
|
|
|
|
68
|
1
|
|
|
|
|
2
|
$start_extra = ''; |
69
|
1
|
|
|
|
|
2
|
$end_extra = '", $end_extra; |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
my $return = $config->{no_file} ? |
88
|
40
|
100
|
|
|
|
213
|
qq~$ie_start$ie_end~ : |
89
|
|
|
|
|
|
|
qq~$ie_start$ie_end~; |
90
|
|
|
|
|
|
|
|
91
|
40
|
100
|
|
|
|
3083
|
$file ? $return : (); |
92
|
|
|
|
|
|
|
} |
93
|
29
|
|
|
|
|
249
|
@{ $c->stash->{__CSSLOADERFILES__} }; |
|
29
|
|
|
|
|
75
|
|
94
|
|
|
|
|
|
|
|
95
|
29
|
100
|
|
|
|
102
|
return if !$load_css; |
96
|
|
|
|
|
|
|
|
97
|
27
|
100
|
|
|
|
38
|
${$content} =~ s!()!$load_css$1! or ${$content} = $load_css . ${$content}; |
|
26
|
|
|
|
|
93
|
|
|
26
|
|
|
|
|
81
|
|
|
27
|
|
|
|
|
113
|
|
98
|
14
|
|
|
|
|
2076
|
}); |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
1; |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
__END__ |