line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mojolicious::Plugin::HTMLTemplateProRenderer; |
2
|
|
|
|
|
|
|
|
3
|
4
|
|
|
4
|
|
2400
|
use 5.006; |
|
4
|
|
|
|
|
11
|
|
|
4
|
|
|
|
|
142
|
|
4
|
4
|
|
|
4
|
|
15
|
use Mojo::Base 'Mojolicious::Plugin'; |
|
4
|
|
|
|
|
6
|
|
|
4
|
|
|
|
|
22
|
|
5
|
|
|
|
|
|
|
|
6
|
4
|
|
|
4
|
|
2527
|
use HTML::Template::Pro; |
|
4
|
|
|
|
|
13599
|
|
|
4
|
|
|
|
|
197
|
|
7
|
4
|
|
|
4
|
|
1957
|
use HTML::Template::Pro::Extension; |
|
4
|
|
|
|
|
5811
|
|
|
4
|
|
|
|
|
2406
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
our $VERSION = '0.04'; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
sub register { |
12
|
4
|
|
|
4
|
1
|
181
|
my ( $self, $app, $conf ) = @_; |
13
|
4
|
|
|
|
|
24
|
$self->{plugin_config} = $conf; |
14
|
4
|
|
|
7
|
|
84
|
$app->renderer->add_handler( tmpl => sub { $self->render_tmpl(@_) } ); |
|
7
|
|
|
|
|
124161
|
|
15
|
|
|
|
|
|
|
} |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub render_tmpl { |
18
|
7
|
|
|
7
|
0
|
21
|
my ( $self, $r, $c, $output, $options ) = @_; |
19
|
7
|
|
|
|
|
18
|
my $conf = $self->{plugin_config}; |
20
|
7
|
|
|
|
|
9
|
my %tmpl_params = %{ $c->stash }; |
|
7
|
|
|
|
|
24
|
|
21
|
|
|
|
|
|
|
|
22
|
7
|
100
|
100
|
|
|
130
|
unshift @{ $r->paths }, $c->app->home |
|
2
|
|
|
|
|
37
|
|
23
|
|
|
|
|
|
|
if ( $conf->{tmpl_opts}->{use_home_template} |
24
|
|
|
|
|
|
|
|| delete $tmpl_params{use_home_template} ); |
25
|
|
|
|
|
|
|
|
26
|
7
|
|
|
|
|
105
|
my $controller = $c->stash('controller'); |
27
|
|
|
|
|
|
|
|
28
|
7
|
|
|
|
|
53
|
my @template_dirs; |
29
|
|
|
|
|
|
|
|
30
|
7
|
|
|
|
|
114
|
push @template_dirs, $c->app->home->rel_dir('templates'); |
31
|
|
|
|
|
|
|
|
32
|
7
|
50
|
|
|
|
607
|
if ($controller) { |
33
|
0
|
|
|
|
|
0
|
push @template_dirs, $c->app->home->rel_dir("templates/$controller"); |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
7
|
|
|
|
|
9
|
my $t; |
37
|
|
|
|
|
|
|
my %t_options; |
38
|
|
|
|
|
|
|
|
39
|
7
|
100
|
66
|
|
|
50
|
if ( $conf->{tmpl_opts}->{use_extension} |
40
|
|
|
|
|
|
|
|| delete $tmpl_params{use_extension} ) |
41
|
|
|
|
|
|
|
{ |
42
|
1
|
50
|
|
|
|
3
|
if ( defined( $options->{inline} ) ) { |
|
|
0
|
|
|
|
|
|
43
|
1
|
|
|
|
|
4
|
$t_options{tmplfile} = \$options->{inline}; |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
elsif ( defined( $options->{template} ) ) { |
46
|
0
|
0
|
|
|
|
0
|
if ( defined( my $path = $r->template_path($options) ) ) { |
47
|
0
|
|
|
|
|
0
|
$t_options{tmplfile} = $path; |
48
|
0
|
|
|
|
|
0
|
$t_options{cache} = 1; |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
else { |
51
|
0
|
|
|
|
|
0
|
$t_options{tmplfile} = \$r->get_data_template($options); |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
1
|
|
50
|
|
|
11
|
my $plugins = $conf->{tmpl_opts}->{plugins} || []; |
56
|
1
|
50
|
|
|
|
4
|
$plugins = [ @$plugins, @{ $tmpl_params{plugins} } ] |
|
1
|
|
|
|
|
3
|
|
57
|
|
|
|
|
|
|
if exists $tmpl_params{plugins}; |
58
|
1
|
|
|
|
|
3
|
$t_options{plugins} = $plugins; |
59
|
1
|
|
|
|
|
10
|
$t = new HTML::Template::Pro::Extension(%t_options); |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
else { |
62
|
6
|
|
|
|
|
14
|
$t_options{die_on_bad_params} = 0; |
63
|
6
|
|
|
|
|
13
|
$t_options{global_vars} = 1; |
64
|
6
|
|
|
|
|
14
|
$t_options{loop_context_vars} = 1; |
65
|
6
|
|
|
|
|
11
|
$t_options{path} = \@template_dirs; |
66
|
6
|
|
|
|
|
14
|
$t_options{search_path_on_include} = 1; |
67
|
|
|
|
|
|
|
|
68
|
6
|
100
|
|
|
|
20
|
if ( defined( $options->{inline} ) ) { |
|
|
50
|
|
|
|
|
|
69
|
2
|
|
|
|
|
5
|
$t_options{scalarref} = \$options->{inline}; |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
elsif ( defined( $options->{template} ) ) { |
72
|
4
|
100
|
|
|
|
17
|
if ( defined( my $path = $r->template_path($options) ) ) { |
73
|
3
|
|
|
|
|
2197
|
$t_options{filename} = $path; |
74
|
3
|
|
|
|
|
9
|
$t_options{cache} = 1; |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
else { |
77
|
1
|
|
|
|
|
100
|
$t_options{scalarref} = $r->get_data_template($options); |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
6
|
50
|
|
|
|
25
|
$t = HTML::Template::Pro->new( |
83
|
|
|
|
|
|
|
%t_options, |
84
|
6
|
50
|
|
|
|
78
|
%{ $conf->{tmpl_opts} || {} }, |
85
|
6
|
|
|
|
|
50
|
%{ delete $tmpl_params{tmpl_opts} || {} } |
86
|
|
|
|
|
|
|
); |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
} |
89
|
7
|
50
|
|
|
|
1620
|
unless ($t) { $r->render_exception("ERROR: No template created"); } |
|
0
|
|
|
|
|
0
|
|
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
# sanity params removing scalar inside arrayref |
92
|
7
|
|
|
|
|
31
|
foreach ( keys %tmpl_params ) { |
93
|
50
|
100
|
66
|
|
|
196
|
delete $tmpl_params{$_} |
|
|
|
100
|
|
|
|
|
94
|
|
|
|
|
|
|
if ( ( ref $tmpl_params{$_} eq 'ARRAY' ) |
95
|
|
|
|
|
|
|
&& $tmpl_params{$_} > 0 |
96
|
|
|
|
|
|
|
&& ref($tmpl_params{$_}->[0]) ne 'HASH' ); |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
|
99
|
7
|
|
|
|
|
45
|
$t->param(%tmpl_params); |
100
|
|
|
|
|
|
|
|
101
|
7
|
|
|
|
|
234
|
$$output = $t->output(); |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
1; |
105
|
|
|
|
|
|
|
__END__ |