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