line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Dancer::Template::Mustache; |
2
|
|
|
|
|
|
|
our $AUTHORITY = 'cpan:YANICK'; |
3
|
|
|
|
|
|
|
# ABSTRACT: Wrapper for the Mustache template system |
4
|
|
|
|
|
|
|
$Dancer::Template::Mustache::VERSION = '1.0.0'; |
5
|
3
|
|
|
3
|
|
85005
|
use strict; |
|
3
|
|
|
|
|
8
|
|
|
3
|
|
|
|
|
118
|
|
6
|
3
|
|
|
3
|
|
15
|
use warnings; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
62
|
|
7
|
|
|
|
|
|
|
|
8
|
3
|
|
|
3
|
|
1298
|
use Template::Mustache; |
|
3
|
|
|
|
|
379813
|
|
|
3
|
|
|
|
|
90
|
|
9
|
3
|
|
|
3
|
|
28
|
use FindBin; |
|
3
|
|
|
|
|
8
|
|
|
3
|
|
|
|
|
149
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
require Dancer; |
12
|
|
|
|
|
|
|
|
13
|
3
|
|
|
3
|
|
20
|
use Moo; |
|
3
|
|
|
|
|
8
|
|
|
3
|
|
|
|
|
21
|
|
14
|
|
|
|
|
|
|
|
15
|
3
|
|
|
3
|
|
1215
|
use Path::Tiny; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
677
|
|
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
require Dancer::Config; |
18
|
|
|
|
|
|
|
Dancer::Config->import( 'setting' ); |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
extends 'Dancer::Template::Abstract'; |
21
|
|
|
|
|
|
|
|
22
|
0
|
|
|
0
|
|
0
|
sub _build_name { 'Dancer::Template::Mustache' } |
23
|
|
|
|
|
|
|
|
24
|
11
|
|
|
11
|
1
|
235493
|
sub default_tmpl_ext { "mustache" }; |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
has _template_path => ( |
27
|
|
|
|
|
|
|
is => 'ro', |
28
|
|
|
|
|
|
|
lazy => 1, |
29
|
|
|
|
|
|
|
default => sub { |
30
|
|
|
|
|
|
|
setting( 'views' ) || $FindBin::Bin . '/views' |
31
|
|
|
|
|
|
|
}, |
32
|
|
|
|
|
|
|
); |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
my %file_template; # cache for the templates |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub render { |
37
|
7
|
|
|
7
|
1
|
3079
|
my ($self, $template, $tokens) = @_; |
38
|
|
|
|
|
|
|
|
39
|
7
|
|
|
|
|
166
|
my $_template_path = $self->_template_path; |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
# remove the views part |
42
|
7
|
|
|
|
|
143
|
$template =~ s#^\Q$_template_path\E/?##; |
43
|
|
|
|
|
|
|
|
44
|
7
|
|
66
|
|
|
114
|
my $mustache = $file_template{$template} ||= Template::Mustache->new( |
45
|
|
|
|
|
|
|
template_path => path( $self->_template_path, $template ) |
46
|
|
|
|
|
|
|
); |
47
|
|
|
|
|
|
|
|
48
|
7
|
|
|
|
|
6730
|
return $mustache->render($tokens); |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
1; |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
__END__ |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
=pod |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
=encoding UTF-8 |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
=head1 NAME |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
Dancer::Template::Mustache - Wrapper for the Mustache template system |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
=head1 VERSION |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
version 1.0.0 |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
=head1 SYNOPSIS |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
# in config.yml |
70
|
|
|
|
|
|
|
template: mustache |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
# in the app |
73
|
|
|
|
|
|
|
get '/style/:style' => sub { |
74
|
|
|
|
|
|
|
template 'style' => { |
75
|
|
|
|
|
|
|
style => param('style') |
76
|
|
|
|
|
|
|
}; |
77
|
|
|
|
|
|
|
}; |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
# in views/style.mustache |
80
|
|
|
|
|
|
|
That's a nice, manly {{style}} mustache you have there! |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
=head1 DESCRIPTION |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
This module is a L<Dancer> wrapper for L<Template::Mustache>. |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
For now, the extension of the mustache templates must be C<.mustache>. |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
Partials are supported, as are layouts. For layouts, the content of the inner |
89
|
|
|
|
|
|
|
template is sent via the usual I<content> template variable. So a typical |
90
|
|
|
|
|
|
|
mustached layout would look like: |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
<body> |
93
|
|
|
|
|
|
|
{{{ content }}} |
94
|
|
|
|
|
|
|
</body> |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
=head1 SEE ALSO |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
The Mustache templating system: L<http://mustache.github.com/> |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
L<Dancer::Template::Handlebars> - Dancer support for Handlebars, a templating system |
101
|
|
|
|
|
|
|
that is a superset of Mustache. |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
=head1 AUTHOR |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
Yanick Champoux <yanick@babyl.dyndns.org> |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
This software is copyright (c) 2017, 2014, 2012 by Yanick Champoux. |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
112
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
=cut |