Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Thanks you @ailin-nemui for the issue #6 kick in the pants
  • Loading branch information
sanko committed Feb 6, 2020
1 parent bd06aa3 commit 42cebef
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 5 deletions.
2 changes: 2 additions & 0 deletions Changes
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

{{$NEXT}}

- Whitespace control (See https://shopify.github.io/liquid/basics/whitespace/)

1.0.13 2020-02-06T01:34:45Z

- Cheap fix for shallow context->get(...) in conditions
Expand Down
10 changes: 5 additions & 5 deletions lib/Template/Liquid/Utility.pm
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ our $FilterSeparator = qr[\s*\|\s*]o;
my $ArgumentSeparator = qr[,]o;
our $FilterArgumentSeparator = qr[\s*:\s*]o;
our $VariableAttributeSeparator = qr[\.]o;
our $TagStart = qr[{%\s*]o;
our $TagEnd = qr[\s*%}]o;
our $TagStart = qr[(?:\s*{%-\s*|{%\s*)]o;
our $TagEnd = qr[(?:\s*-%}\s+?|\s*%})]o;
our $VariableSignature = qr{\(?[\w\-\.\[\]]\)?}o;
my $VariableSegment = qr[[\w\-]\??]ox;
our $VariableStart = qr[\{\{\s*]o;
Expand All @@ -26,20 +26,20 @@ our $Expression = qr/(?:${QuotedFragment}(?:${SpacelessFilter})*)/o;
our $TagAttributes = qr[(\w+)(?:\s*\:\s*(${QuotedFragment}))?]o;
my $AnyStartingTag = qr[\{\{|\{\%]o;
my $PartialTemplateParser
= qr[${TagStart}.*?${TagEnd}|${VariableStart}.*?${VariableIncompleteEnd}]o;
= qr[${TagStart}.+?${TagEnd}|${VariableStart}.*?${VariableIncompleteEnd}]os;
my $TemplateParser = qr[(${PartialTemplateParser}|${AnyStartingTag})]o;
our $VariableParser = qr[^
${VariableStart} # {{
([\w\.]+) # name
(?:\s*\|\s*(.+)\s*)? # filters
${VariableEnd} # }}
$]ox;
$]sox;
our $VariableFilterArgumentParser
= qr[\s*,\s*(?=(?:[^\']*\'[^\']*\')*(?![^\']*\'))]o;
our $TagMatch = qr[^${Template::Liquid::Utility::TagStart} # {%
(.+?) # etc
${Template::Liquid::Utility::TagEnd} # %}
$]ox;
$]sox;
our $VarMatch = qr[^
${Template::Liquid::Utility::VariableStart} # {{
(.+?) # stuff + filters?
Expand Down
42 changes: 42 additions & 0 deletions t/0200_tags/02101_whitespace_control.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
use strict;
use warnings;
use lib qw[../../lib ../../blib/lib];
use Test::More; # Requires 0.94 as noted in Build.PL
use Template::Liquid;
$|++;
is( Template::Liquid->parse(
<<'TEMPLATE')->render(), ' Wow, John G. Chalmers-Smith, you have a long name!', 'whitespace control');
{%- assign username = "John G. Chalmers-Smith" -%}
{%- if username and username.size > 10 -%}
Wow, {{ username }}, you have a long name!
{%- else -%}
Hello there!
{%- endif -%}
TEMPLATE
is( Template::Liquid->parse(
<<'TEMPLATE')->render(), <<'EXPECTED', 'without whitespace control');
{% assign username = "John G. Chalmers-Smith" %}
{% if username and username.size > 10 %}
Wow, {{ username }}, you have a long name!
{% else %}
Hello there!
{% endif %}
TEMPLATE


Wow, John G. Chalmers-Smith, you have a long name!

EXPECTED
is( Template::Liquid->parse(
<<'TEMPLATE')->render(), <<'EXPECTED', 'mixed with and without whitespace control');
{%-assign username = "John G. Chalmers-Smith"-%}
{%-if username and username.size > 10 %}
Wow, {{ username }}, you have a long name!
{%else%}
Hello there!
{%endif-%}
TEMPLATE

Wow, John G. Chalmers-Smith, you have a long name!
EXPECTED
done_testing();

0 comments on commit 42cebef

Please sign in to comment.