line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mojolicious::Plugin::Template::Mustache; |
2
|
1
|
|
|
1
|
|
714
|
use Mojo::Base 'Mojolicious::Plugin'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
8
|
|
3
|
|
|
|
|
|
|
|
4
|
1
|
|
|
1
|
|
708
|
use Template::Mustache; |
|
1
|
|
|
|
|
140667
|
|
|
1
|
|
|
|
|
298
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = '0.02'; |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
sub register { |
9
|
1
|
|
|
1
|
1
|
69
|
my ($self, $app, $args) = @_; |
10
|
|
|
|
|
|
|
|
11
|
1
|
|
50
|
|
|
12
|
$args //= {}; |
12
|
1
|
|
|
|
|
15
|
my $mustache = Template::Mustache->new(%$args); |
13
|
1
|
|
|
|
|
2099
|
$Template::Mustache::template_path = ''; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
$app->renderer->add_handler(mustache => sub { |
16
|
3
|
|
|
3
|
|
48855
|
my ($renderer, $c, $output, $options) = @_; |
17
|
|
|
|
|
|
|
|
18
|
3
|
100
|
|
|
|
23
|
if ($options->{inline}) { |
|
|
100
|
|
|
|
|
|
19
|
1
|
|
|
|
|
4
|
my $inline_template = $options->{inline}; |
20
|
1
|
50
|
|
|
|
12
|
$$output = $mustache->render($inline_template, $c->stash) if $inline_template; |
21
|
|
|
|
|
|
|
} |
22
|
|
|
|
|
|
|
elsif (my $template_name = $renderer->template_path($options)) { |
23
|
1
|
|
|
|
|
147
|
$Template::Mustache::template_file = $template_name; |
24
|
1
|
|
|
|
|
5
|
$$output = $mustache->render($c->stash); |
25
|
|
|
|
|
|
|
} else { |
26
|
1
|
|
|
|
|
1920
|
my $data_template = $renderer->get_data_template($options); |
27
|
1
|
50
|
|
|
|
51
|
$$output = $mustache->render($data_template, $c->stash) if $data_template; |
28
|
|
|
|
|
|
|
} |
29
|
3
|
50
|
|
|
|
7389
|
return $$output ? 1 : 0; |
30
|
1
|
|
|
|
|
12
|
}); |
31
|
|
|
|
|
|
|
|
32
|
1
|
|
|
|
|
36
|
return 1; |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
1; |
36
|
|
|
|
|
|
|
__END__ |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
=encoding utf8 |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
=head1 NAME |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
Mojolicious::Plugin::Template::Mustache - Mojolicious Plugin |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
=head1 SYNOPSIS |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
# Mojolicious |
47
|
|
|
|
|
|
|
$self->plugin('Template::Mustache'); |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
# Mojolicious::Lite |
50
|
|
|
|
|
|
|
plugin 'Template::Mustache'; |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
get '/inline' => sub { |
53
|
|
|
|
|
|
|
my $c = shift; |
54
|
|
|
|
|
|
|
$c->render( |
55
|
|
|
|
|
|
|
handler => 'mustache', |
56
|
|
|
|
|
|
|
inline => 'Inline hello, {{message}}!', |
57
|
|
|
|
|
|
|
message => 'Mustache', |
58
|
|
|
|
|
|
|
); |
59
|
|
|
|
|
|
|
}; |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
=head1 DESCRIPTION |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
L<Mojolicious::Plugin::Template::Mustache> is a L<Mojolicious> plugin. |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
=head1 METHODS |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
L<Mojolicious::Plugin::Template::Mustache> inherits all methods from L<Mojolicious::Plugin>. |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
=head1 SEE ALSO |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
L<Mojolicious>, L<Mojolicious::Guides>, L<http://mojolicious.org>, L<http://mustache.github.io>, L<Template::Mustache>. |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
=head2 AUTHOR |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
Cyrill Novgorodcev E<lt>cynovg@cpan.orgE<gt> |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
=head2 LICENSE |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
Copyright 2017 Cyrill Novgorodcev. |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
This program is free software: you can redistribute it and/or modify |
82
|
|
|
|
|
|
|
it under the terms of the GNU General Public License as published by |
83
|
|
|
|
|
|
|
the Free Software Foundation, either version 3 of the License, or |
84
|
|
|
|
|
|
|
(at your option) any later version. |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful, |
87
|
|
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of |
88
|
|
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
89
|
|
|
|
|
|
|
GNU General Public License for more details. |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License |
92
|
|
|
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>. |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
=cut |
95
|
|
|
|
|
|
|
|