Skip to content

Commit 8602f1c

Browse files
committed
Rename template render to 'template'
'render' is already used heavily with 'render_error' and 'render_response'. Template does not render in the same sense - it just returns a string content of the parsed template. For this reason it must be renamed.
1 parent 7761337 commit 8602f1c

7 files changed

Lines changed: 28 additions & 28 deletions

File tree

ex/controllers/lib/ControllerApp/Controller/Clock.pm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ sub build ($self)
1818

1919
sub show_clock ($self, $ctx)
2020
{
21-
return $self->render(\*DATA);
21+
return $self->template(\*DATA);
2222
}
2323

2424
__DATA__

ex/full-app/lib/FullApp.pm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ sub build ($self)
1717

1818
sub welcome_page ($self, $ctx)
1919
{
20-
return $self->render(
20+
return $self->template(
2121
'welcome', {
2222
config => $self->config->config,
2323
api_url => $self->url_for('location_list_api'),

ex/sse/app.pl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ ($self)
2929

3030
sub init_sse ($self, $ctx)
3131
{
32-
return $self->render(\*DATA);
32+
return $self->template(\*DATA);
3333
}
3434

3535
async sub handle_sse ($self, $ctx)

ex/websocket/app.pl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ ($self)
2929

3030
sub init_ws ($self, $ctx)
3131
{
32-
return $self->render(\*DATA);
32+
return $self->template(\*DATA);
3333
}
3434

3535
async sub handle_ws ($self, $ctx)

lib/Thunderhorse.pm

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -779,9 +779,9 @@ during request processing.
779779
780780
=head3 Template
781781
782-
The Template module (L<Thunderhorse::Module::Template>) adds template
783-
rendering capabilities using L<Template::Toolkit>. It adds a C<render> method to
784-
controllers.
782+
The Template module (L<Thunderhorse::Module::Template>) adds template rendering
783+
capabilities using L<Template::Toolkit>. It adds a
784+
L<Thunderhorse::Module::Template/template> method to controllers.
785785
786786
Loading the module:
787787
@@ -813,7 +813,7 @@ Once loaded, templates can be rendered from controller methods:
813813
814814
sub show_page ($self, $ctx)
815815
{
816-
return $self->render('page', {
816+
return $self->template('page', {
817817
title => 'My Page',
818818
content => 'Hello, World!',
819819
});
@@ -834,12 +834,12 @@ If the first argument is passed as the reference, the behavior changes:
834834
835835
=back
836836
837-
For simple apps, it is often useful to render from C<DATA>. GLOB refs will be
837+
For simple apps, it is often useful to parse C<DATA>. GLOB refs will be
838838
rolled back after reading them automatically.
839839
840840
sub render_data ($self, $ctx)
841841
{
842-
return $self->render(\*DATA);
842+
return $self->template(\*DATA);
843843
}
844844
845845
=head3 Middleware

lib/Thunderhorse/Module/Template.pm

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ sub build ($self)
2626
my $tpl = $self->template;
2727

2828
$self->add_method(
29-
controller => render => sub ($controller, $template, $vars = {}) {
29+
controller => template => sub ($controller, $template, $vars = {}) {
3030
return $tpl->process($template, $vars);
3131
}
3232
);
@@ -51,22 +51,22 @@ Thunderhorse::Module::Template - Template module for Thunderhorse
5151
# in controller method
5252
sub show_page ($self, $ctx)
5353
{
54-
return $self->render('page', {
54+
return $self->template('page', {
5555
title => 'My Page',
5656
content => 'Hello, World!',
5757
});
5858
}
5959
60-
# render from DATA handle
60+
# parse DATA handle
6161
sub render_data ($self, $ctx)
6262
{
63-
return $self->render(\*DATA);
63+
return $self->template(\*DATA);
6464
}
6565
6666
=head1 DESCRIPTION
6767
6868
The Template module adds template rendering capabilities using
69-
L<Template::Toolkit>. It adds a L</render> method to controllers.
69+
L<Template::Toolkit>. It adds a L</template> method to controllers.
7070
7171
=head1 CONFIGURATION
7272
@@ -91,17 +91,17 @@ case they will be ignored.
9191
9292
=head2 Controller Methods
9393
94-
=head3 render
94+
=head3 template
9595
96-
$self->render('page', { title => 'My Page' });
97-
$self->render(\*DATA);
98-
$self->render(\$template_string);
96+
$self->template('page', { title => 'My Page' });
97+
$self->template(\*DATA);
98+
$self->template(\$template_string);
9999
100-
Renders a template and returns the rendered content. The first argument is the
101-
template name (C<.tt> suffix will be added automatically), and the second is a
102-
hash reference of variables to pass to the template. The method returns the
103-
rendered content, which is then sent to the client as HTML (if the context is
104-
not already consumed).
100+
Parses a template and returns the content. The first argument is the template
101+
name (C<.tt> suffix will be added automatically), and the second is a hash
102+
reference of variables to pass to the template. The method returns the parsed
103+
content, which can then be returned from the handler to be sent to the client
104+
as HTML (if the context is not already consumed).
105105
106106
If the first argument is passed as a reference, the behavior changes:
107107

t/module/template.t

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,22 +51,22 @@ package TemplateApp {
5151
sub test ($self, $ctx, $ex)
5252
{
5353
$ex = defined $ex ? ".$ex" : '';
54-
return $self->render("test$ex", {name => 'World'});
54+
return $self->template("test$ex", {name => 'World'});
5555
}
5656

5757
sub test_inline ($self, $ctx)
5858
{
59-
return $self->render(\'Hello [% name %]!', {name => 'Inline'});
59+
return $self->template(\'Hello [% name %]!', {name => 'Inline'});
6060
}
6161

6262
sub test_data ($self, $ctx)
6363
{
64-
return $self->render(\*main::DATA);
64+
return $self->template(\*main::DATA);
6565
}
6666

6767
sub test_bad ($self, $ctx)
6868
{
69-
return $self->render('bad_template');
69+
return $self->template('bad_template');
7070
}
7171
}
7272

0 commit comments

Comments
 (0)