line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package MojoX::Renderer::Haml; |
2
|
|
|
|
|
|
|
our $VERSION = '2.100000'; |
3
|
|
|
|
|
|
|
|
4
|
3
|
|
|
3
|
|
2448
|
use warnings; |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
98
|
|
5
|
3
|
|
|
3
|
|
18
|
use strict; |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
104
|
|
6
|
|
|
|
|
|
|
|
7
|
3
|
|
|
3
|
|
26
|
use base 'Mojo::Base'; |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
2423
|
|
8
|
|
|
|
|
|
|
|
9
|
3
|
|
|
3
|
|
24087
|
use Mojo::ByteStream 'b'; |
|
3
|
|
|
|
|
254246
|
|
|
3
|
|
|
|
|
207
|
|
10
|
3
|
|
|
3
|
|
2080
|
use Mojo::Exception; |
|
3
|
|
|
|
|
5384
|
|
|
3
|
|
|
|
|
34
|
|
11
|
3
|
|
|
3
|
|
3590
|
use Text::Haml; |
|
3
|
|
|
|
|
72558
|
|
|
3
|
|
|
|
|
1926
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
__PACKAGE__->attr(haml_args=>sub { return {}; }); |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub build { |
16
|
1
|
|
|
1
|
0
|
8
|
my $self = shift->SUPER::new(@_); |
17
|
1
|
|
|
|
|
11
|
my %args=@_; |
18
|
1
|
|
|
|
|
26
|
$self->haml_args(\%args); |
19
|
11
|
|
|
11
|
|
166516
|
return sub { $self->_render(@_) } |
20
|
1
|
|
|
|
|
14
|
} |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
my $ESCAPE = <<'EOF'; |
23
|
|
|
|
|
|
|
my $v = shift; |
24
|
|
|
|
|
|
|
ref $v && ref $v eq 'Mojo::ByteStream' |
25
|
|
|
|
|
|
|
? "$v" |
26
|
|
|
|
|
|
|
: Mojo::ByteStream->new($v)->xml_escape->to_string; |
27
|
|
|
|
|
|
|
EOF |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub _render { |
30
|
11
|
|
|
11
|
|
42
|
my ($self, $r, $c, $output, $options) = @_; |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
# TODO: Handle $options->{inline} ? |
33
|
11
|
|
|
|
|
172
|
my $name = $r->template_name($options); |
34
|
11
|
50
|
|
|
|
165
|
return unless defined $name; |
35
|
|
|
|
|
|
|
|
36
|
11
|
|
|
|
|
19
|
my $path; |
37
|
|
|
|
|
|
|
# FIXME: Does anything set this stash var? Does it ever exist? |
38
|
11
|
50
|
|
|
|
39
|
unless ($path = $c->stash->{'template_path'}) { |
39
|
11
|
|
|
|
|
227
|
$path = $r->template_path($options); |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
11
|
|
|
|
|
1028
|
my $list = join ', ', sort keys %{$c->stash}; |
|
11
|
|
|
|
|
40
|
|
43
|
|
|
|
|
|
|
# If this is a data template path may be blank but name should be what we want. |
44
|
11
|
|
33
|
|
|
213
|
my $cache_key = $path || $name; |
45
|
11
|
|
|
|
|
84
|
my $cache = b("$cache_key($list)")->md5_sum->to_string; |
46
|
|
|
|
|
|
|
|
47
|
11
|
|
100
|
|
|
438
|
$r->{_haml_cache} ||= {}; |
48
|
|
|
|
|
|
|
|
49
|
11
|
|
|
|
|
18
|
my $t = $name; |
50
|
|
|
|
|
|
|
|
51
|
11
|
|
|
|
|
28
|
my $haml = $r->{_haml_cache}->{$cache}; |
52
|
|
|
|
|
|
|
|
53
|
11
|
|
|
|
|
315
|
my %args = (app => $c->app, %{$c->stash}); |
|
11
|
|
|
|
|
99
|
|
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
# Interpret again |
56
|
11
|
50
|
33
|
|
|
392
|
if ( $c->app->mode ne 'development' && $haml && $haml->compiled) { |
|
|
|
33
|
|
|
|
|
57
|
0
|
|
|
|
|
0
|
$haml->helpers_arg($c); |
58
|
|
|
|
|
|
|
|
59
|
0
|
|
|
|
|
0
|
$c->app->log->debug("Rendering cached $t."); |
60
|
0
|
|
|
|
|
0
|
$$output = $haml->interpret(%args); |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
# No cache |
64
|
|
|
|
|
|
|
else { |
65
|
11
|
|
66
|
|
|
422
|
$haml ||= Text::Haml->new(escape => $ESCAPE,%{$self->{haml_args}}); |
|
8
|
|
|
|
|
70
|
|
66
|
|
|
|
|
|
|
|
67
|
11
|
|
|
|
|
1092
|
$haml->helpers_arg($c); |
68
|
11
|
|
|
|
|
356
|
$haml->helpers($r->helpers); |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
# Try template |
71
|
11
|
50
|
33
|
|
|
201
|
if ($path && -r $path) { |
|
|
100
|
|
|
|
|
|
72
|
0
|
|
|
|
|
0
|
$c->app->log->debug("Rendering template '$t'."); |
73
|
0
|
|
|
|
|
0
|
$$output = $haml->render_file($path, %args); |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
# Try DATA section |
77
|
|
|
|
|
|
|
# as of Mojolicious 3.34 get_data_template discards $t |
78
|
|
|
|
|
|
|
elsif (my $d = $r->get_data_template($options, $t)) { |
79
|
9
|
|
|
|
|
507
|
$c->app->log->debug("Rendering template '$t' from DATA section."); |
80
|
9
|
|
|
|
|
1043
|
$$output = $haml->render($d, %args); |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
# No template |
84
|
|
|
|
|
|
|
else { |
85
|
2
|
|
|
|
|
84
|
$c->app->log->debug(qq/Template "$t" missing or not readable./); |
86
|
2
|
|
|
|
|
141
|
return; |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
9
|
100
|
|
|
|
47488
|
unless (defined $$output) { |
91
|
1
|
|
|
|
|
4
|
$$output = ''; |
92
|
1
|
|
|
|
|
7
|
die(qq/Template error in "$t": / . $haml->error); |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
|
95
|
8
|
|
66
|
|
|
228
|
$r->{_haml_cache}->{$cache} ||= $haml; |
96
|
|
|
|
|
|
|
|
97
|
8
|
50
|
|
|
|
80
|
return ref $$output ? die($$output) : 1; |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
1; |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
=head1 NAME |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
MojoX::Renderer::Haml - Mojolicious renderer for HAML templates. |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
=head1 SYNOPSIS |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
my $haml = MojoX::Renderer::Haml->build(%$args, mojo => $app); |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
# Add "haml" handler |
111
|
|
|
|
|
|
|
$app->renderer->add_handler(haml => $haml); |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
=head1 DESCRIPTION |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
This module is a renderer for L templates. normally, you |
116
|
|
|
|
|
|
|
just want to use L. |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
=head1 CREDITS |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
Marcus Ramberg, C |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
Randy Stauner, C |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
=head1 AUTHOR |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
Viacheslav Tykhanovskyi, C. |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
Currently maintained by Breno G. de Oliveira, C. |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
=head1 COPYRIGHT |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
Copyright (C) 2008-2012, Viacheslav Tykhanovskyi. |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
This program is free software, you can redistribute it and/or modify it under |
135
|
|
|
|
|
|
|
the same terms as Perl 5.10. |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
=cut |