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