mirror of
https://github.com/Shopify/liquid.git
synced 2026-09-20 03:10:39 -07:00
Add whitespace control character and associated tests
This commit is contained in:
+2
-1
@@ -24,6 +24,7 @@ module Liquid
|
|||||||
ArgumentSeparator = ','.freeze
|
ArgumentSeparator = ','.freeze
|
||||||
FilterArgumentSeparator = ':'.freeze
|
FilterArgumentSeparator = ':'.freeze
|
||||||
VariableAttributeSeparator = '.'.freeze
|
VariableAttributeSeparator = '.'.freeze
|
||||||
|
WhitespaceControl = '-'.freeze
|
||||||
TagStart = /\{\%/
|
TagStart = /\{\%/
|
||||||
TagEnd = /\%\}/
|
TagEnd = /\%\}/
|
||||||
VariableSignature = /\(?[\w\-\.\[\]]\)?/
|
VariableSignature = /\(?[\w\-\.\[\]]\)?/
|
||||||
@@ -34,7 +35,7 @@ module Liquid
|
|||||||
QuotedString = /"[^"]*"|'[^']*'/
|
QuotedString = /"[^"]*"|'[^']*'/
|
||||||
QuotedFragment = /#{QuotedString}|(?:[^\s,\|'"]|#{QuotedString})+/o
|
QuotedFragment = /#{QuotedString}|(?:[^\s,\|'"]|#{QuotedString})+/o
|
||||||
TagAttributes = /(\w+)\s*\:\s*(#{QuotedFragment})/o
|
TagAttributes = /(\w+)\s*\:\s*(#{QuotedFragment})/o
|
||||||
AnyStartingTag = /\{\{|\{\%/
|
AnyStartingTag = /#{TagStart}|#{VariableStart}/o
|
||||||
PartialTemplateParser = /#{TagStart}.*?#{TagEnd}|#{VariableStart}.*?#{VariableIncompleteEnd}/om
|
PartialTemplateParser = /#{TagStart}.*?#{TagEnd}|#{VariableStart}.*?#{VariableIncompleteEnd}/om
|
||||||
TemplateParser = /(#{PartialTemplateParser}|#{AnyStartingTag})/om
|
TemplateParser = /(#{PartialTemplateParser}|#{AnyStartingTag})/om
|
||||||
VariableParser = /\[[^\]]+\]|#{VariableSegment}+\??/o
|
VariableParser = /\[[^\]]+\]|#{VariableSegment}+\??/o
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
module Liquid
|
module Liquid
|
||||||
class BlockBody
|
class BlockBody
|
||||||
FullToken = /\A#{TagStart}\s*(\w+)\s*(.*)?#{TagEnd}\z/om
|
FullToken = /\A#{TagStart}#{WhitespaceControl}?\s*(\w+)\s*(.*?)#{WhitespaceControl}?#{TagEnd}\z/om
|
||||||
ContentOfVariable = /\A#{VariableStart}(.*)#{VariableEnd}\z/om
|
ContentOfVariable = /\A#{VariableStart}#{WhitespaceControl}?(.*?)#{WhitespaceControl}?#{VariableEnd}\z/om
|
||||||
TAGSTART = "{%".freeze
|
TAGSTART = "{%".freeze
|
||||||
VARSTART = "{{".freeze
|
VARSTART = "{{".freeze
|
||||||
|
|
||||||
@@ -18,6 +18,7 @@ module Liquid
|
|||||||
unless token.empty?
|
unless token.empty?
|
||||||
case
|
case
|
||||||
when token.start_with?(TAGSTART)
|
when token.start_with?(TAGSTART)
|
||||||
|
whitespace_handler(token, parse_context)
|
||||||
if token =~ FullToken
|
if token =~ FullToken
|
||||||
tag_name = $1
|
tag_name = $1
|
||||||
markup = $2
|
markup = $2
|
||||||
@@ -35,9 +36,14 @@ module Liquid
|
|||||||
raise_missing_tag_terminator(token, parse_context)
|
raise_missing_tag_terminator(token, parse_context)
|
||||||
end
|
end
|
||||||
when token.start_with?(VARSTART)
|
when token.start_with?(VARSTART)
|
||||||
|
whitespace_handler(token, parse_context)
|
||||||
@nodelist << create_variable(token, parse_context)
|
@nodelist << create_variable(token, parse_context)
|
||||||
@blank = false
|
@blank = false
|
||||||
else
|
else
|
||||||
|
if parse_context.trim_whitespace
|
||||||
|
token.lstrip!
|
||||||
|
end
|
||||||
|
parse_context.trim_whitespace = false
|
||||||
@nodelist << token
|
@nodelist << token
|
||||||
@blank &&= !!(token =~ /\A\s*\z/)
|
@blank &&= !!(token =~ /\A\s*\z/)
|
||||||
end
|
end
|
||||||
@@ -48,6 +54,17 @@ module Liquid
|
|||||||
yield nil, nil
|
yield nil, nil
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def whitespace_handler(token, parse_context)
|
||||||
|
if token[2] == WhitespaceControl
|
||||||
|
previous_token = @nodelist.pop
|
||||||
|
if previous_token.is_a? String
|
||||||
|
previous_token.rstrip!
|
||||||
|
@nodelist << previous_token
|
||||||
|
end
|
||||||
|
end
|
||||||
|
parse_context.trim_whitespace = (token[-3] == WhitespaceControl)
|
||||||
|
end
|
||||||
|
|
||||||
def blank?
|
def blank?
|
||||||
@blank
|
@blank
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
module Liquid
|
module Liquid
|
||||||
class ParseContext
|
class ParseContext
|
||||||
attr_accessor :locale, :line_number
|
attr_accessor :locale, :line_number, :trim_whitespace
|
||||||
attr_reader :partial, :warnings, :error_mode
|
attr_reader :partial, :warnings, :error_mode
|
||||||
|
|
||||||
def initialize(options = {})
|
def initialize(options = {})
|
||||||
|
|||||||
@@ -97,6 +97,22 @@ class ErrorHandlingTest < Minitest::Test
|
|||||||
assert_match(/Liquid syntax error \(line 4\)/, err.message)
|
assert_match(/Liquid syntax error \(line 4\)/, err.message)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_with_line_numbers_adds_numbers_to_parser_errors_with_whitespace_trim
|
||||||
|
err = assert_raises(SyntaxError) do
|
||||||
|
Liquid::Template.parse(%q(
|
||||||
|
foobar
|
||||||
|
|
||||||
|
{%- "cat" | foobar -%}
|
||||||
|
|
||||||
|
bla
|
||||||
|
),
|
||||||
|
line_numbers: true
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
assert_match(/Liquid syntax error \(line 4\)/, err.message)
|
||||||
|
end
|
||||||
|
|
||||||
def test_parsing_warn_with_line_numbers_adds_numbers_to_lexer_errors
|
def test_parsing_warn_with_line_numbers_adds_numbers_to_lexer_errors
|
||||||
template = Liquid::Template.parse('
|
template = Liquid::Template.parse('
|
||||||
foobar
|
foobar
|
||||||
|
|||||||
@@ -0,0 +1,525 @@
|
|||||||
|
require 'test_helper'
|
||||||
|
|
||||||
|
class TrimModeTest < Minitest::Test
|
||||||
|
include Liquid
|
||||||
|
|
||||||
|
# Make sure the trim isn't applied to standard output
|
||||||
|
def test_standard_output
|
||||||
|
text = <<-END_TEMPLATE
|
||||||
|
<div>
|
||||||
|
<p>
|
||||||
|
{{ 'John' }}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
END_TEMPLATE
|
||||||
|
expected = <<-END_EXPECTED
|
||||||
|
<div>
|
||||||
|
<p>
|
||||||
|
John
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
END_EXPECTED
|
||||||
|
assert_template_result(expected, text)
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_variable_output_with_multiple_blank_lines
|
||||||
|
text = <<-END_TEMPLATE
|
||||||
|
<div>
|
||||||
|
<p>
|
||||||
|
|
||||||
|
|
||||||
|
{{- 'John' -}}
|
||||||
|
|
||||||
|
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
END_TEMPLATE
|
||||||
|
expected = <<-END_EXPECTED
|
||||||
|
<div>
|
||||||
|
<p>John</p>
|
||||||
|
</div>
|
||||||
|
END_EXPECTED
|
||||||
|
assert_template_result(expected, text)
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_tag_output_with_multiple_blank_lines
|
||||||
|
text = <<-END_TEMPLATE
|
||||||
|
<div>
|
||||||
|
<p>
|
||||||
|
|
||||||
|
|
||||||
|
{%- if true -%}
|
||||||
|
yes
|
||||||
|
{%- endif -%}
|
||||||
|
|
||||||
|
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
END_TEMPLATE
|
||||||
|
expected = <<-END_EXPECTED
|
||||||
|
<div>
|
||||||
|
<p>yes</p>
|
||||||
|
</div>
|
||||||
|
END_EXPECTED
|
||||||
|
assert_template_result(expected, text)
|
||||||
|
end
|
||||||
|
|
||||||
|
# Make sure the trim isn't applied to standard tags
|
||||||
|
def test_standard_tags
|
||||||
|
whitespace = ' '
|
||||||
|
text = <<-END_TEMPLATE
|
||||||
|
<div>
|
||||||
|
<p>
|
||||||
|
{% if true %}
|
||||||
|
yes
|
||||||
|
{% endif %}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
END_TEMPLATE
|
||||||
|
expected = <<-END_EXPECTED
|
||||||
|
<div>
|
||||||
|
<p>
|
||||||
|
#{whitespace}
|
||||||
|
yes
|
||||||
|
#{whitespace}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
END_EXPECTED
|
||||||
|
assert_template_result(expected, text)
|
||||||
|
|
||||||
|
text = <<-END_TEMPLATE
|
||||||
|
<div>
|
||||||
|
<p>
|
||||||
|
{% if false %}
|
||||||
|
no
|
||||||
|
{% endif %}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
END_TEMPLATE
|
||||||
|
expected = <<-END_EXPECTED
|
||||||
|
<div>
|
||||||
|
<p>
|
||||||
|
#{whitespace}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
END_EXPECTED
|
||||||
|
assert_template_result(expected, text)
|
||||||
|
end
|
||||||
|
|
||||||
|
# Make sure the trim isn't too agressive
|
||||||
|
def test_no_trim_output
|
||||||
|
text = '<p>{{- \'John\' -}}</p>'
|
||||||
|
expected = '<p>John</p>'
|
||||||
|
assert_template_result(expected, text)
|
||||||
|
end
|
||||||
|
|
||||||
|
# Make sure the trim isn't too agressive
|
||||||
|
def test_no_trim_tags
|
||||||
|
text = '<p>{%- if true -%}yes{%- endif -%}</p>'
|
||||||
|
expected = '<p>yes</p>'
|
||||||
|
assert_template_result(expected, text)
|
||||||
|
|
||||||
|
text = '<p>{%- if false -%}no{%- endif -%}</p>'
|
||||||
|
expected = '<p></p>'
|
||||||
|
assert_template_result(expected, text)
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_single_line_outer_tag
|
||||||
|
text = '<p> {%- if true %} yes {% endif -%} </p>'
|
||||||
|
expected = '<p> yes </p>'
|
||||||
|
assert_template_result(expected, text)
|
||||||
|
|
||||||
|
text = '<p> {%- if false %} no {% endif -%} </p>'
|
||||||
|
expected = '<p></p>'
|
||||||
|
assert_template_result(expected, text)
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_single_line_inner_tag
|
||||||
|
text = '<p> {% if true -%} yes {%- endif %} </p>'
|
||||||
|
expected = '<p> yes </p>'
|
||||||
|
assert_template_result(expected, text)
|
||||||
|
|
||||||
|
text = '<p> {% if false -%} no {%- endif %} </p>'
|
||||||
|
expected = '<p> </p>'
|
||||||
|
assert_template_result(expected, text)
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_single_line_post_tag
|
||||||
|
text = '<p> {% if true -%} yes {% endif -%} </p>'
|
||||||
|
expected = '<p> yes </p>'
|
||||||
|
assert_template_result(expected, text)
|
||||||
|
|
||||||
|
text = '<p> {% if false -%} no {% endif -%} </p>'
|
||||||
|
expected = '<p> </p>'
|
||||||
|
assert_template_result(expected, text)
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_single_line_pre_tag
|
||||||
|
text = '<p> {%- if true %} yes {%- endif %} </p>'
|
||||||
|
expected = '<p> yes </p>'
|
||||||
|
assert_template_result(expected, text)
|
||||||
|
|
||||||
|
text = '<p> {%- if false %} no {%- endif %} </p>'
|
||||||
|
expected = '<p> </p>'
|
||||||
|
assert_template_result(expected, text)
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_pre_trim_output
|
||||||
|
text = <<-END_TEMPLATE
|
||||||
|
<div>
|
||||||
|
<p>
|
||||||
|
{{- 'John' }}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
END_TEMPLATE
|
||||||
|
expected = <<-END_EXPECTED
|
||||||
|
<div>
|
||||||
|
<p>John
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
END_EXPECTED
|
||||||
|
assert_template_result(expected, text)
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_pre_trim_tags
|
||||||
|
text = <<-END_TEMPLATE
|
||||||
|
<div>
|
||||||
|
<p>
|
||||||
|
{%- if true %}
|
||||||
|
yes
|
||||||
|
{%- endif %}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
END_TEMPLATE
|
||||||
|
expected = <<-END_EXPECTED
|
||||||
|
<div>
|
||||||
|
<p>
|
||||||
|
yes
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
END_EXPECTED
|
||||||
|
assert_template_result(expected, text)
|
||||||
|
|
||||||
|
text = <<-END_TEMPLATE
|
||||||
|
<div>
|
||||||
|
<p>
|
||||||
|
{%- if false %}
|
||||||
|
no
|
||||||
|
{%- endif %}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
END_TEMPLATE
|
||||||
|
expected = <<-END_EXPECTED
|
||||||
|
<div>
|
||||||
|
<p>
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
END_EXPECTED
|
||||||
|
assert_template_result(expected, text)
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_post_trim_output
|
||||||
|
text = <<-END_TEMPLATE
|
||||||
|
<div>
|
||||||
|
<p>
|
||||||
|
{{ 'John' -}}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
END_TEMPLATE
|
||||||
|
expected = <<-END_EXPECTED
|
||||||
|
<div>
|
||||||
|
<p>
|
||||||
|
John</p>
|
||||||
|
</div>
|
||||||
|
END_EXPECTED
|
||||||
|
assert_template_result(expected, text)
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_post_trim_tags
|
||||||
|
text = <<-END_TEMPLATE
|
||||||
|
<div>
|
||||||
|
<p>
|
||||||
|
{% if true -%}
|
||||||
|
yes
|
||||||
|
{% endif -%}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
END_TEMPLATE
|
||||||
|
expected = <<-END_EXPECTED
|
||||||
|
<div>
|
||||||
|
<p>
|
||||||
|
yes
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
END_EXPECTED
|
||||||
|
assert_template_result(expected, text)
|
||||||
|
|
||||||
|
text = <<-END_TEMPLATE
|
||||||
|
<div>
|
||||||
|
<p>
|
||||||
|
{% if false -%}
|
||||||
|
no
|
||||||
|
{% endif -%}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
END_TEMPLATE
|
||||||
|
expected = <<-END_EXPECTED
|
||||||
|
<div>
|
||||||
|
<p>
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
END_EXPECTED
|
||||||
|
assert_template_result(expected, text)
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_pre_and_post_trim_tags
|
||||||
|
text = <<-END_TEMPLATE
|
||||||
|
<div>
|
||||||
|
<p>
|
||||||
|
{%- if true %}
|
||||||
|
yes
|
||||||
|
{% endif -%}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
END_TEMPLATE
|
||||||
|
expected = <<-END_EXPECTED
|
||||||
|
<div>
|
||||||
|
<p>
|
||||||
|
yes
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
END_EXPECTED
|
||||||
|
assert_template_result(expected, text)
|
||||||
|
|
||||||
|
text = <<-END_TEMPLATE
|
||||||
|
<div>
|
||||||
|
<p>
|
||||||
|
{%- if false %}
|
||||||
|
no
|
||||||
|
{% endif -%}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
END_TEMPLATE
|
||||||
|
expected = <<-END_EXPECTED
|
||||||
|
<div>
|
||||||
|
<p></p>
|
||||||
|
</div>
|
||||||
|
END_EXPECTED
|
||||||
|
assert_template_result(expected, text)
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_post_and_pre_trim_tags
|
||||||
|
text = <<-END_TEMPLATE
|
||||||
|
<div>
|
||||||
|
<p>
|
||||||
|
{% if true -%}
|
||||||
|
yes
|
||||||
|
{%- endif %}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
END_TEMPLATE
|
||||||
|
expected = <<-END_EXPECTED
|
||||||
|
<div>
|
||||||
|
<p>
|
||||||
|
yes
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
END_EXPECTED
|
||||||
|
assert_template_result(expected, text)
|
||||||
|
|
||||||
|
whitespace = ' '
|
||||||
|
text = <<-END_TEMPLATE
|
||||||
|
<div>
|
||||||
|
<p>
|
||||||
|
{% if false -%}
|
||||||
|
no
|
||||||
|
{%- endif %}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
END_TEMPLATE
|
||||||
|
expected = <<-END_EXPECTED
|
||||||
|
<div>
|
||||||
|
<p>
|
||||||
|
#{whitespace}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
END_EXPECTED
|
||||||
|
assert_template_result(expected, text)
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_trim_output
|
||||||
|
text = <<-END_TEMPLATE
|
||||||
|
<div>
|
||||||
|
<p>
|
||||||
|
{{- 'John' -}}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
END_TEMPLATE
|
||||||
|
expected = <<-END_EXPECTED
|
||||||
|
<div>
|
||||||
|
<p>John</p>
|
||||||
|
</div>
|
||||||
|
END_EXPECTED
|
||||||
|
assert_template_result(expected, text)
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_trim_tags
|
||||||
|
text = <<-END_TEMPLATE
|
||||||
|
<div>
|
||||||
|
<p>
|
||||||
|
{%- if true -%}
|
||||||
|
yes
|
||||||
|
{%- endif -%}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
END_TEMPLATE
|
||||||
|
expected = <<-END_EXPECTED
|
||||||
|
<div>
|
||||||
|
<p>yes</p>
|
||||||
|
</div>
|
||||||
|
END_EXPECTED
|
||||||
|
assert_template_result(expected, text)
|
||||||
|
|
||||||
|
text = <<-END_TEMPLATE
|
||||||
|
<div>
|
||||||
|
<p>
|
||||||
|
{%- if false -%}
|
||||||
|
no
|
||||||
|
{%- endif -%}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
END_TEMPLATE
|
||||||
|
expected = <<-END_EXPECTED
|
||||||
|
<div>
|
||||||
|
<p></p>
|
||||||
|
</div>
|
||||||
|
END_EXPECTED
|
||||||
|
assert_template_result(expected, text)
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_whitespace_trim_output
|
||||||
|
text = <<-END_TEMPLATE
|
||||||
|
<div>
|
||||||
|
<p>
|
||||||
|
{{- 'John' -}},
|
||||||
|
{{- '30' -}}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
END_TEMPLATE
|
||||||
|
expected = <<-END_EXPECTED
|
||||||
|
<div>
|
||||||
|
<p>John,30</p>
|
||||||
|
</div>
|
||||||
|
END_EXPECTED
|
||||||
|
assert_template_result(expected, text)
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_whitespace_trim_tags
|
||||||
|
text = <<-END_TEMPLATE
|
||||||
|
<div>
|
||||||
|
<p>
|
||||||
|
{%- if true -%}
|
||||||
|
yes
|
||||||
|
{%- endif -%}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
END_TEMPLATE
|
||||||
|
expected = <<-END_EXPECTED
|
||||||
|
<div>
|
||||||
|
<p>yes</p>
|
||||||
|
</div>
|
||||||
|
END_EXPECTED
|
||||||
|
assert_template_result(expected, text)
|
||||||
|
|
||||||
|
text = <<-END_TEMPLATE
|
||||||
|
<div>
|
||||||
|
<p>
|
||||||
|
{%- if false -%}
|
||||||
|
no
|
||||||
|
{%- endif -%}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
END_TEMPLATE
|
||||||
|
expected = <<-END_EXPECTED
|
||||||
|
<div>
|
||||||
|
<p></p>
|
||||||
|
</div>
|
||||||
|
END_EXPECTED
|
||||||
|
assert_template_result(expected, text)
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_complex_trim_output
|
||||||
|
text = <<-END_TEMPLATE
|
||||||
|
<div>
|
||||||
|
<p>
|
||||||
|
{{- 'John' -}}
|
||||||
|
{{- '30' -}}
|
||||||
|
</p>
|
||||||
|
<b>
|
||||||
|
{{ 'John' -}}
|
||||||
|
{{- '30' }}
|
||||||
|
</b>
|
||||||
|
<i>
|
||||||
|
{{- 'John' }}
|
||||||
|
{{ '30' -}}
|
||||||
|
</i>
|
||||||
|
</div>
|
||||||
|
END_TEMPLATE
|
||||||
|
expected = <<-END_EXPECTED
|
||||||
|
<div>
|
||||||
|
<p>John30</p>
|
||||||
|
<b>
|
||||||
|
John30
|
||||||
|
</b>
|
||||||
|
<i>John
|
||||||
|
30</i>
|
||||||
|
</div>
|
||||||
|
END_EXPECTED
|
||||||
|
assert_template_result(expected, text)
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_complex_trim
|
||||||
|
text = <<-END_TEMPLATE
|
||||||
|
<div>
|
||||||
|
{%- if true -%}
|
||||||
|
{%- if true -%}
|
||||||
|
<p>
|
||||||
|
{{- 'John' -}}
|
||||||
|
</p>
|
||||||
|
{%- endif -%}
|
||||||
|
{%- endif -%}
|
||||||
|
</div>
|
||||||
|
END_TEMPLATE
|
||||||
|
expected = <<-END_EXPECTED
|
||||||
|
<div><p>John</p></div>
|
||||||
|
END_EXPECTED
|
||||||
|
assert_template_result(expected, text)
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_raw_output
|
||||||
|
whitespace = ' '
|
||||||
|
text = <<-END_TEMPLATE
|
||||||
|
<div>
|
||||||
|
{% raw %}
|
||||||
|
{%- if true -%}
|
||||||
|
<p>
|
||||||
|
{{- 'John' -}}
|
||||||
|
</p>
|
||||||
|
{%- endif -%}
|
||||||
|
{% endraw %}
|
||||||
|
</div>
|
||||||
|
END_TEMPLATE
|
||||||
|
expected = <<-END_EXPECTED
|
||||||
|
<div>
|
||||||
|
#{whitespace}
|
||||||
|
{%- if true -%}
|
||||||
|
<p>
|
||||||
|
{{- 'John' -}}
|
||||||
|
</p>
|
||||||
|
{%- endif -%}
|
||||||
|
#{whitespace}
|
||||||
|
</div>
|
||||||
|
END_EXPECTED
|
||||||
|
assert_template_result(expected, text)
|
||||||
|
end
|
||||||
|
end # TrimModeTest
|
||||||
Reference in New Issue
Block a user