line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mojolicious::Plugin::ContextResources; |
2
|
4
|
|
|
4
|
|
96737
|
use Mojo::Base 'Mojolicious::Plugin'; |
|
4
|
|
|
|
|
135537
|
|
|
4
|
|
|
|
|
26
|
|
3
|
4
|
|
|
4
|
|
2013
|
use File::Spec::Functions qw(catfile); |
|
4
|
|
|
|
|
763
|
|
|
4
|
|
|
|
|
2644
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
our $VERSION = '0.02'; |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
# Get current context path |
8
|
|
|
|
|
|
|
sub _context($) { |
9
|
8
|
|
|
8
|
|
19
|
my ($c) = @_; |
10
|
|
|
|
|
|
|
|
11
|
8
|
|
|
|
|
18
|
my @path; |
12
|
8
|
|
|
|
|
24
|
my $stash = $c->stash; |
13
|
8
|
100
|
66
|
|
|
104
|
if( $stash->{'controller'} && $stash->{'action'} ) { |
|
|
50
|
|
|
|
|
|
14
|
4
|
|
|
|
|
18
|
push @path, split m{[/\-]}, $stash->{'controller'}; |
15
|
4
|
|
|
|
|
20
|
push @path, $stash->{'action'}; |
16
|
|
|
|
|
|
|
} elsif( $stash->{'mojo.captures'}{'template'} ) { |
17
|
4
|
|
|
|
|
12
|
push @path, $stash->{'mojo.captures'}{'template'}; |
18
|
|
|
|
|
|
|
} |
19
|
8
|
|
|
|
|
27
|
return @path; |
20
|
|
|
|
|
|
|
} |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub register { |
23
|
3
|
|
|
3
|
1
|
122
|
my ($self, $app, $conf) = @_; |
24
|
|
|
|
|
|
|
|
25
|
3
|
|
50
|
|
|
12
|
$conf ||= {}; |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
# Path |
28
|
3
|
|
33
|
|
|
33
|
$conf->{home} //= $app->home; |
29
|
3
|
|
50
|
|
|
95
|
$conf->{public} //= 'public'; |
30
|
3
|
|
50
|
|
|
15
|
$conf->{js} //= '/js'; |
31
|
3
|
|
50
|
|
|
13
|
$conf->{css} //= '/css'; |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
$app->helper(url_context_stylesheet => sub { |
34
|
4
|
|
|
4
|
|
32454
|
my ($c) = @_; |
35
|
|
|
|
|
|
|
|
36
|
4
|
|
|
|
|
22
|
my @path = _context( $c ); |
37
|
4
|
50
|
|
|
|
27
|
return undef unless @path; |
38
|
|
|
|
|
|
|
|
39
|
4
|
|
|
|
|
35
|
my $file = catfile( $conf->{css}, @path ) . '.css'; |
40
|
4
|
|
|
|
|
40
|
my $path = $conf->{home}->rel_file(catfile $conf->{public}, $file); |
41
|
4
|
100
|
|
|
|
132
|
return undef unless -f $path; |
42
|
|
|
|
|
|
|
|
43
|
2
|
|
|
|
|
80
|
return Mojo::URL->new( $file ); |
44
|
3
|
|
|
|
|
22
|
}); |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
$app->helper(url_context_javascript => sub { |
47
|
4
|
|
|
4
|
|
20106
|
my ($c) = @_; |
48
|
|
|
|
|
|
|
|
49
|
4
|
|
|
|
|
24
|
my @path = _context( $c ); |
50
|
4
|
50
|
|
|
|
20
|
return undef unless @path; |
51
|
|
|
|
|
|
|
|
52
|
4
|
|
|
|
|
31
|
my $file = catfile( $conf->{js}, @path ) . '.js'; |
53
|
4
|
|
|
|
|
43
|
my $path = $conf->{home}->rel_file(catfile $conf->{public}, $file); |
54
|
4
|
100
|
|
|
|
114
|
return undef unless -f $path; |
55
|
|
|
|
|
|
|
|
56
|
2
|
|
|
|
|
69
|
return Mojo::URL->new( $file ); |
57
|
3
|
|
|
|
|
79
|
}); |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
$app->helper(stylesheet_context => sub { |
60
|
2
|
|
|
2
|
|
39096
|
my ($c) = @_; |
61
|
|
|
|
|
|
|
|
62
|
2
|
|
|
|
|
22
|
my $url = $c->url_context_stylesheet; |
63
|
2
|
100
|
|
|
|
129
|
return Mojo::ByteStream->new('') unless $url; |
64
|
|
|
|
|
|
|
|
65
|
1
|
|
|
|
|
17
|
return Mojo::ByteStream->new( $c->stylesheet( $url )); |
66
|
3
|
|
|
|
|
48
|
}); |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
$app->helper(javascript_context => sub { |
69
|
2
|
|
|
2
|
|
658
|
my ($c) = @_; |
70
|
|
|
|
|
|
|
|
71
|
2
|
|
|
|
|
15
|
my $url = $c->url_context_javascript; |
72
|
2
|
100
|
|
|
|
107
|
return Mojo::ByteStream->new('') unless $url; |
73
|
|
|
|
|
|
|
|
74
|
1
|
|
|
|
|
16
|
return Mojo::ByteStream->new( $c->javascript( $url )); |
75
|
3
|
|
|
|
|
50
|
}); |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
1; |
79
|
|
|
|
|
|
|
__END__ |