line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package MojoX::Renderer::Handlebars; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
20608
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
26
|
|
4
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
26
|
|
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
4
|
use File::Spec (); |
|
1
|
|
|
|
|
5
|
|
|
1
|
|
|
|
|
28
|
|
7
|
1
|
|
|
1
|
|
747
|
use Mojo::Base -base; |
|
1
|
|
|
|
|
10937
|
|
|
1
|
|
|
|
|
7
|
|
8
|
1
|
|
|
1
|
|
871
|
use Mojo::Loader qw(data_section); |
|
1
|
|
|
|
|
138738
|
|
|
1
|
|
|
|
|
64
|
|
9
|
1
|
|
|
1
|
|
852
|
use Text::Handlebars (); |
|
1
|
|
|
|
|
15659
|
|
|
1
|
|
|
|
|
520
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
our $VERSION = '0.04'; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
has 'handlebars'; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub build { |
17
|
0
|
|
|
0
|
1
|
|
my $self = shift->SUPER::new(@_); |
18
|
0
|
|
|
|
|
|
$self->_init(@_); |
19
|
0
|
|
|
0
|
|
|
return sub { $self->_render(@_) }; |
|
0
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
} |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub _init { |
23
|
0
|
|
|
0
|
|
|
my ($self, %args) = @_; |
24
|
|
|
|
|
|
|
|
25
|
0
|
|
0
|
|
|
|
my $app = $args{mojo} || $args{app}; |
26
|
0
|
|
|
|
|
|
my $cache_dir; |
27
|
0
|
|
|
|
|
|
my @path = $app->home->rel_dir('templates'); |
28
|
|
|
|
|
|
|
|
29
|
0
|
0
|
|
|
|
|
if ($app) { |
30
|
0
|
|
|
|
|
|
$cache_dir = $app->home->rel_dir('tmp/compiled_templates'); |
31
|
0
|
|
|
|
|
|
push @path, data_section( $app->renderer->classes->[0] ); |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
else { |
34
|
0
|
|
|
|
|
|
$cache_dir = File::Spec->tmpdir; |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
my %config = ( |
38
|
|
|
|
|
|
|
cache_dir => $cache_dir, |
39
|
|
|
|
|
|
|
path => \@path, |
40
|
|
|
|
0
|
|
|
warn_handler => sub { }, |
41
|
|
|
|
0
|
|
|
die_handler => sub { }, |
42
|
0
|
0
|
|
|
|
|
%{$args{template_options} || {}}, |
|
0
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
); |
44
|
|
|
|
|
|
|
|
45
|
0
|
|
|
|
|
|
$self->handlebars(Text::Handlebars->new(\%config)); |
46
|
|
|
|
|
|
|
|
47
|
0
|
|
|
|
|
|
return $self; |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
sub _render { |
51
|
0
|
|
|
0
|
|
|
my ($self, $renderer, $c, $output, $options) = @_; |
52
|
|
|
|
|
|
|
|
53
|
0
|
|
0
|
|
|
|
my $name = $c->stash->{'template_name'} |
54
|
|
|
|
|
|
|
|| $renderer->template_name($options); |
55
|
0
|
|
|
|
|
|
my %params = (%{$c->stash}, c => $c); |
|
0
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
|
57
|
0
|
|
|
|
|
|
local $@; |
58
|
0
|
0
|
|
|
|
|
if (defined(my $inline = $options->{inline})) { |
59
|
0
|
|
|
|
|
|
$$output = $self->handlebars->render_string($inline, \%params); |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
else { |
62
|
0
|
|
|
|
|
|
$$output = $self->handlebars->render($name, \%params); |
63
|
|
|
|
|
|
|
} |
64
|
0
|
0
|
|
|
|
|
die $@ if $@; |
65
|
|
|
|
|
|
|
|
66
|
0
|
|
|
|
|
|
return 1; |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
1; |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
__END__ |