-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathTtRenderer.pm
196 lines (118 loc) · 3.49 KB
/
TtRenderer.pm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
package Mojolicious::Plugin::TtRenderer;
use strict;
use warnings;
use 5.016;
# ABSTRACT: Template Renderer Plugin for Mojolicious
# VERSION
use base 'Mojolicious::Plugin';
use Mojolicious::Plugin::TtRenderer::Engine;
sub register {
my ($self, $app, $args) = @_;
$args ||= {};
my $tt = Mojolicious::Plugin::TtRenderer::Engine->build(%$args, app => $app);
# Add "tt" handler
$app->renderer->add_handler(tt => $tt);
}
$Mojolicious::Plugin::TtRenderer::VERSION //= ('devel');
1;
__END__
=encoding utf-8
=begin stopwords
Bjørn
Szász
Árpád
Романов
Сергей
=end stopwords
=head1 SYNOPSIS
L<Mojolicious::Lite>:
plugin 'tt_renderer';
L<Mojolicious>:
$self->plugin('tt_renderer');
=head1 DESCRIPTION
This plugin is a simple Template Toolkit renderer for L<Mojolicious>.
Its defaults are usually reasonable, although for finer grain detail in
configuration you may want to use
L<Mojolicious::Plugin::TtRenderer::Engine> directly.
=head1 OPTIONS
These are the options that can be passed in as arguments to this plugin.
=head2 template_options
Configuration hash passed into L<Template>'s constructor, see
L<Template Toolkit's configuration summary|Template#CONFIGURATION-SUMMARY>
for details. Here is an example using the L<Mojolicious::Lite> form:
plugin 'tt_renderer' => {
template_options => {
PRE_CHOMP => 1,
POST_CHOMP => 1,
TRIM => 1,
},
};
Here is the same example using the full L<Mojolicious> app form:
package MyApp;
use Mojo::Base qw( Mojolicious );
sub startup {
my($self) = @_;
$self->plugin('tt_renderer' => {
template_options => {
PRE_CHOMP => 1,
POST_CHOMP => 1,
TRIM => 1,
},
}
...
}
These options will be used if you do not override them:
=over 4
=item INCLUDE_PATH
Generated based on your application's renderer's configuration. It
will include all renderer paths, in addition to search files located
in the C<__DATA__> section by the usual logic used by L<Mojolicious>.
=item COMPILE_EXT
C<.ttc>
=item UNICODE
C<1> (true)
=item ENCODING
C<utf-87>
=item CACHE_SIZE
C<128>
=item RELATIVE
C<1> (true)
=back
=head2 cache_dir
Specifies the directory in which compiled template files are
written. This:
plugin 'tt_renderer', { cache_dir => 'some/path' };
is equivalent to
plugin 'tt_renderer', { template_options { COMPILE_DIR => 'some/path' } };
except in the first example relative paths are relative to the L<Mojolicious>
app's home directory (C<$app-E<gt>home>).
=head1 STASH
=head2 h
Helpers are available via the C<h> entry in the stash.
<a href="[% h.url_for('index') %]">go back to index</a>
=head2 c
The current controller instance can be accessed as C<c>.
I see you are requesting a document from [% c.req.headers.host %].
=head1 EXAMPLES
=over 4
=item L<Mojolicious::Lite> example:
# EXAMPLE: example/myapp.pl
=item L<Mojolicious> example:
C<lib/MyApp.pm>:
# EXAMPLE: example/myapp/lib/MyApp.pm
C<lib/MyApp/Example.pm>:
# EXAMPLE: example/myapp/lib/MyApp/Example.pm
C<templates/example/welcome.html.tt>:
# EXAMPLE: example/myapp/templates/example/welcome.html.tt
C<templates/layouts/default.html.tt>:
# EXAMPLE: example/myapp/templates/layouts/default.html.tt
=back
These are also included with the C<Mojolicious::Plugin::TtRenderer>
distribution, including the support files required for the full
L<Mojolicious> app example.
=head1 SEE ALSO
L<Mojolicious::Plugin::TtRenderer::Engine>,
L<Mojolicious>,
L<Mojolicious::Guides>,
L<http://mojolicious.org>.
=cut