Skip to content

Commit

Permalink
explain newline handling at the end of templates (closes #1041)
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Jan 20, 2017
1 parent db9c97c commit a377c9a
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
6 changes: 6 additions & 0 deletions lib/Mojo/Template.pm
Expand Up @@ -374,6 +374,12 @@ backslash.
in multiple\\
lines
A newline character gets appended automatically to every template, unless the
last character is a backslash. And empty lines at the end of a template are
ignored.
There is <%= 1 + 1 %> no newline at the end here\
You can capture whole template blocks for reuse later with the C<begin> and
C<end> keywords. Just be aware that both keywords are part of the surrounding
tag and not actual Perl code, so there can only be whitespace after C<begin>
Expand Down
6 changes: 6 additions & 0 deletions lib/Mojolicious/Guides/Rendering.pod
Expand Up @@ -145,6 +145,12 @@ backslash.
in multiple\\
lines

A newline character gets appended automatically to every template, unless the
last character is a backslash. And empty lines at the end of a template are
ignored.

There is <%= 1 + 1 %> no newline at the end here\

At the beginning of the template, stash values that don't have invalid
characters in their name get automatically initialized as normal variables, and
the controller object as both C<$self> and C<$c>.
Expand Down
7 changes: 6 additions & 1 deletion t/mojo/template.t
Expand Up @@ -1050,10 +1050,15 @@ $mt = Mojo::Template->new;
$output = $mt->render("test\n\n123\n\n<% %>456\n789");
is $output, "test\n\n123\n\n456\n789\n", 'empty statement';

# No newline
$mt = Mojo::Template->new;
$output = $mt->render('test');
is $output, "test\n", 'just one newline';

# Multiple newlines
$mt = Mojo::Template->new;
$output = $mt->render("test\n\n\n\n");
is $output, "test\n", 'just one newline remaining';
is $output, "test\n", 'just one newline';

# Optimize successive text lines ending with newlines
$mt = Mojo::Template->new;
Expand Down

0 comments on commit a377c9a

Please sign in to comment.