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