line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Catalyst::Helper::View::Xslate; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
1206
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
702
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
=head1 NAME |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
Catalyst::Helper::View::Xslate - Helper for Xslate Views |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
=head1 SYNOPSIS |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
For a standard (Kolon) syntax |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
script/create.pl view HTML Xslate |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
Alternatively, for a Template-Toolkit syntax: |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
script/create.pl view HTML Xslate bridge=TT2 syntax=TTerse |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
=head1 DESCRIPTION |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
This is a helper module for Xslate Views. It is not meant to be used |
23
|
|
|
|
|
|
|
directly. Instead, you should use your Catalyst app's "create" script |
24
|
|
|
|
|
|
|
(see the SYNOPSIS for syntax). |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
=head2 Arguments |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
As any other view helper, the first argument is your View's name. In the |
29
|
|
|
|
|
|
|
synopsys example we used "HTML", and it's usually a good name :) |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
The Xslate helper accepts the same construction arguments as |
32
|
|
|
|
|
|
|
L<Text::Xslate itself|Text::Xslate>. |
33
|
|
|
|
|
|
|
List arguments can be separated by comma: |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
script/create.pl view HTML Xslate cache=2 header=foo.tx,bar.tx suffix=.tt |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
For convenience, it also takes the following argument: |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
C<bridge> - The optional bridge method. It can be set to C<TT2> for |
40
|
|
|
|
|
|
|
L<Template-Toolkit|Template> compatibility, or C<TT2Like> for a similar |
41
|
|
|
|
|
|
|
layer, but that doesn't require Template-Toolkit installed at all. |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
So, if you specify C<bridge=TT2Like> (for example), you'll automatically get: |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
module => [ 'Text::Xslate::Bridge::TT2Like' ] |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
If you also wish to use TT's syntax, remember to also pass C<syntax=TTerse> |
48
|
|
|
|
|
|
|
on the command line. |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
=head2 METHODS |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
=head3 mk_compclass |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
This method is used by the Catalyst helper engine to generate files properly. |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
=cut |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
sub mk_compclass { |
59
|
0
|
|
|
0
|
1
|
0
|
my ( $self, $helper, @args ) = @_; |
60
|
|
|
|
|
|
|
|
61
|
0
|
|
|
|
|
0
|
my $file = $helper->{file}; |
62
|
0
|
|
|
|
|
0
|
my $template = 'compclass'; |
63
|
|
|
|
|
|
|
|
64
|
0
|
0
|
|
|
|
0
|
if ( @args ) { |
65
|
0
|
|
|
|
|
0
|
$helper->{loader_args} = _build_strings(_parse_args(@args)); |
66
|
0
|
|
|
|
|
0
|
$template .= 'extended'; |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
0
|
|
|
|
|
0
|
$helper->render_file( $template, $file ); |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
sub _parse_args { |
73
|
1
|
|
|
1
|
|
1056
|
my $args = {}; |
74
|
|
|
|
|
|
|
|
75
|
1
|
|
|
|
|
4
|
my %need_array = map { $_, 1 } qw(path module header footer); |
|
4
|
|
|
|
|
14
|
|
76
|
1
|
|
|
|
|
4
|
my %need_hash = map { $_, 1 } qw(function); |
|
1
|
|
|
|
|
3
|
|
77
|
|
|
|
|
|
|
|
78
|
1
|
|
|
|
|
5
|
foreach my $item (@_) { |
79
|
5
|
|
|
|
|
25
|
my ($key, $value) = split /=(?![>])/, $item; |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
# the bridge key is a special case |
82
|
5
|
100
|
|
|
|
17
|
if ($key eq 'bridge') { |
83
|
1
|
|
|
|
|
2
|
$key = 'module'; |
84
|
1
|
|
|
|
|
4
|
$value = 'Text::Xslate::Bridge::' . $value; |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
5
|
100
|
|
|
|
14
|
if ( exists $need_array{$key} ) { |
|
|
100
|
|
|
|
|
|
88
|
3
|
|
|
|
|
4
|
push @{ $args->{$key} }, split /,/, $value; |
|
3
|
|
|
|
|
17
|
|
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
elsif (exists $need_hash{$key} ) { |
91
|
1
|
|
|
|
|
4
|
$args->{$key}->{'data'} = $value; |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
else { |
94
|
1
|
|
|
|
|
3
|
$args->{$key} = $value; |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
} |
97
|
1
|
|
|
|
|
7
|
return $args; |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
sub _build_strings { |
101
|
1
|
|
|
1
|
|
1816
|
my $args = shift; |
102
|
1
|
|
|
|
|
4
|
my $return = {}; |
103
|
|
|
|
|
|
|
|
104
|
1
|
|
|
|
|
5
|
foreach my $key (keys %$args) { |
105
|
5
|
|
|
|
|
11
|
my $ref = ref $args->{$key}; |
106
|
|
|
|
|
|
|
|
107
|
5
|
|
|
|
|
11
|
my $value = ''; |
108
|
5
|
100
|
|
|
|
21
|
if (!$ref) { |
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
109
|
1
|
|
|
|
|
4
|
$value = q[ default => '] . $args->{$key} . q[' ]; |
110
|
|
|
|
|
|
|
} |
111
|
|
|
|
|
|
|
elsif ($ref eq 'HASH') { |
112
|
1
|
|
|
|
|
7
|
$value = $/ |
113
|
|
|
|
|
|
|
. ' default => sub { { ' |
114
|
|
|
|
|
|
|
. $args->{$key}->{'data'} |
115
|
|
|
|
|
|
|
. ' } }' |
116
|
|
|
|
|
|
|
. $/ |
117
|
|
|
|
|
|
|
; |
118
|
|
|
|
|
|
|
} |
119
|
|
|
|
|
|
|
elsif ($ref eq 'ARRAY') { |
120
|
5
|
|
|
|
|
20
|
$value = $/ |
121
|
|
|
|
|
|
|
. ' default => sub { [ ' |
122
|
3
|
|
|
|
|
10
|
. (join ', ', map { "'$_'" } @{$args->{$key}} ) |
|
3
|
|
|
|
|
11
|
|
123
|
|
|
|
|
|
|
. ' ] }' |
124
|
|
|
|
|
|
|
. $/ |
125
|
|
|
|
|
|
|
; |
126
|
|
|
|
|
|
|
} |
127
|
5
|
|
|
|
|
13
|
$return->{$key} = $value; |
128
|
|
|
|
|
|
|
} |
129
|
1
|
|
|
|
|
6
|
return $return; |
130
|
|
|
|
|
|
|
} |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
=head1 SEE ALSO |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
L<Catalyst::View::Xslate>, L<Catalyst::Manual>, L<Catalyst::Helper>, |
135
|
|
|
|
|
|
|
L<Text::Xslate>. |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
=head1 AUTHOR |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
Breno G. de Oliveira C<< <garu@cpan.org> >> |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
=head1 LICENSE |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
This library is free software . You can redistribute it and/or modify |
144
|
|
|
|
|
|
|
it under the same terms as perl itself. |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
=cut |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
1; |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
__DATA__ |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
=begin pod_to_ignore |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
__compclass__ |
155
|
|
|
|
|
|
|
package [% class %]; |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
use strict; |
158
|
|
|
|
|
|
|
use warnings; |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
use base 'Catalyst::View::Xslate'; |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
__PACKAGE__->config( |
163
|
|
|
|
|
|
|
template_extension => '.tx', |
164
|
|
|
|
|
|
|
); |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
1; |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
=head1 NAME |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
[% class %] - Xslate View for [% app %] |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
=head1 DESCRIPTION |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
Xslate View for [% app %]. |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
=cut |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
__compclassextended__ |
179
|
|
|
|
|
|
|
package [% class %]; |
180
|
|
|
|
|
|
|
use Moose; |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
extends 'Catalyst::View::Xslate'; |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
[% FOREACH key = loader_args.keys -%] |
185
|
|
|
|
|
|
|
has '+[% key %]' => ([% loader_args.${key} %]); |
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
[% END -%] |
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
1; |
190
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
=head1 NAME |
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
[% class %] - Xslate View for [% app %] |
194
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
=head1 DESCRIPTION |
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
Xslate View for [% app %]. |
198
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
=cut |