liquid 5.1.0 → 5.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/History.md +35 -0
- data/README.md +4 -4
- data/lib/liquid/block_body.rb +6 -6
- data/lib/liquid/condition.rb +7 -1
- data/lib/liquid/context.rb +6 -2
- data/lib/liquid/expression.rb +11 -10
- data/lib/liquid/forloop_drop.rb +44 -1
- data/lib/liquid/locales/en.yml +6 -5
- data/lib/liquid/partial_cache.rb +3 -3
- data/lib/liquid/registers.rb +51 -0
- data/lib/liquid/standardfilters.rb +463 -75
- data/lib/liquid/strainer_factory.rb +15 -10
- data/lib/liquid/strainer_template.rb +9 -0
- data/lib/liquid/tablerowloop_drop.rb +58 -1
- data/lib/liquid/tags/assign.rb +12 -8
- data/lib/liquid/tags/break.rb +8 -0
- data/lib/liquid/tags/capture.rb +13 -10
- data/lib/liquid/tags/case.rb +21 -0
- data/lib/liquid/tags/comment.rb +13 -0
- data/lib/liquid/tags/continue.rb +8 -9
- data/lib/liquid/tags/cycle.rb +12 -11
- data/lib/liquid/tags/decrement.rb +16 -17
- data/lib/liquid/tags/echo.rb +16 -9
- data/lib/liquid/tags/for.rb +22 -43
- data/lib/liquid/tags/if.rb +11 -9
- data/lib/liquid/tags/include.rb +15 -13
- data/lib/liquid/tags/increment.rb +16 -14
- data/lib/liquid/tags/inline_comment.rb +43 -0
- data/lib/liquid/tags/raw.rb +11 -0
- data/lib/liquid/tags/render.rb +29 -4
- data/lib/liquid/tags/table_row.rb +22 -0
- data/lib/liquid/tags/unless.rb +15 -4
- data/lib/liquid/template.rb +2 -3
- data/lib/liquid/variable.rb +4 -4
- data/lib/liquid/variable_lookup.rb +10 -7
- data/lib/liquid/version.rb +1 -1
- data/lib/liquid.rb +4 -4
- metadata +7 -121
- data/lib/liquid/register.rb +0 -6
- data/lib/liquid/static_registers.rb +0 -44
- data/test/fixtures/en_locale.yml +0 -9
- data/test/integration/assign_test.rb +0 -117
- data/test/integration/blank_test.rb +0 -109
- data/test/integration/block_test.rb +0 -58
- data/test/integration/capture_test.rb +0 -58
- data/test/integration/context_test.rb +0 -636
- data/test/integration/document_test.rb +0 -21
- data/test/integration/drop_test.rb +0 -257
- data/test/integration/error_handling_test.rb +0 -272
- data/test/integration/expression_test.rb +0 -46
- data/test/integration/filter_test.rb +0 -189
- data/test/integration/hash_ordering_test.rb +0 -25
- data/test/integration/output_test.rb +0 -125
- data/test/integration/parsing_quirks_test.rb +0 -134
- data/test/integration/profiler_test.rb +0 -213
- data/test/integration/security_test.rb +0 -89
- data/test/integration/standard_filter_test.rb +0 -880
- data/test/integration/tag/disableable_test.rb +0 -59
- data/test/integration/tag_test.rb +0 -45
- data/test/integration/tags/break_tag_test.rb +0 -17
- data/test/integration/tags/continue_tag_test.rb +0 -17
- data/test/integration/tags/echo_test.rb +0 -13
- data/test/integration/tags/for_tag_test.rb +0 -466
- data/test/integration/tags/if_else_tag_test.rb +0 -190
- data/test/integration/tags/include_tag_test.rb +0 -269
- data/test/integration/tags/increment_tag_test.rb +0 -25
- data/test/integration/tags/liquid_tag_test.rb +0 -116
- data/test/integration/tags/raw_tag_test.rb +0 -34
- data/test/integration/tags/render_tag_test.rb +0 -213
- data/test/integration/tags/standard_tag_test.rb +0 -303
- data/test/integration/tags/statements_test.rb +0 -113
- data/test/integration/tags/table_row_test.rb +0 -66
- data/test/integration/tags/unless_else_tag_test.rb +0 -28
- data/test/integration/template_test.rb +0 -340
- data/test/integration/trim_mode_test.rb +0 -563
- data/test/integration/variable_test.rb +0 -138
- data/test/test_helper.rb +0 -207
- data/test/unit/block_unit_test.rb +0 -53
- data/test/unit/condition_unit_test.rb +0 -168
- data/test/unit/file_system_unit_test.rb +0 -37
- data/test/unit/i18n_unit_test.rb +0 -39
- data/test/unit/lexer_unit_test.rb +0 -53
- data/test/unit/parse_tree_visitor_test.rb +0 -261
- data/test/unit/parser_unit_test.rb +0 -84
- data/test/unit/partial_cache_unit_test.rb +0 -128
- data/test/unit/regexp_unit_test.rb +0 -46
- data/test/unit/static_registers_unit_test.rb +0 -156
- data/test/unit/strainer_factory_unit_test.rb +0 -100
- data/test/unit/strainer_template_unit_test.rb +0 -82
- data/test/unit/tag_unit_test.rb +0 -23
- data/test/unit/tags/case_tag_unit_test.rb +0 -12
- data/test/unit/tags/for_tag_unit_test.rb +0 -15
- data/test/unit/tags/if_tag_unit_test.rb +0 -10
- data/test/unit/template_factory_unit_test.rb +0 -12
- data/test/unit/template_unit_test.rb +0 -87
- data/test/unit/tokenizer_unit_test.rb +0 -62
- data/test/unit/variable_unit_test.rb +0 -164
@@ -1,109 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'test_helper'
|
4
|
-
|
5
|
-
class FoobarTag < Liquid::Tag
|
6
|
-
def render_to_output_buffer(_context, output)
|
7
|
-
output << ' '
|
8
|
-
output
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
|
-
class BlankTestFileSystem
|
13
|
-
def read_template_file(template_path)
|
14
|
-
template_path
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
class BlankTest < Minitest::Test
|
19
|
-
include Liquid
|
20
|
-
N = 10
|
21
|
-
|
22
|
-
def wrap_in_for(body)
|
23
|
-
"{% for i in (1..#{N}) %}#{body}{% endfor %}"
|
24
|
-
end
|
25
|
-
|
26
|
-
def wrap_in_if(body)
|
27
|
-
"{% if true %}#{body}{% endif %}"
|
28
|
-
end
|
29
|
-
|
30
|
-
def wrap(body)
|
31
|
-
wrap_in_for(body) + wrap_in_if(body)
|
32
|
-
end
|
33
|
-
|
34
|
-
def test_new_tags_are_not_blank_by_default
|
35
|
-
with_custom_tag('foobar', FoobarTag) do
|
36
|
-
assert_template_result(" " * N, wrap_in_for("{% foobar %}"))
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
def test_loops_are_blank
|
41
|
-
assert_template_result("", wrap_in_for(" "))
|
42
|
-
end
|
43
|
-
|
44
|
-
def test_if_else_are_blank
|
45
|
-
assert_template_result("", "{% if true %} {% elsif false %} {% else %} {% endif %}")
|
46
|
-
end
|
47
|
-
|
48
|
-
def test_unless_is_blank
|
49
|
-
assert_template_result("", wrap("{% unless true %} {% endunless %}"))
|
50
|
-
end
|
51
|
-
|
52
|
-
def test_mark_as_blank_only_during_parsing
|
53
|
-
assert_template_result(" " * (N + 1), wrap(" {% if false %} this never happens, but still, this block is not blank {% endif %}"))
|
54
|
-
end
|
55
|
-
|
56
|
-
def test_comments_are_blank
|
57
|
-
assert_template_result("", wrap(" {% comment %} whatever {% endcomment %} "))
|
58
|
-
end
|
59
|
-
|
60
|
-
def test_captures_are_blank
|
61
|
-
assert_template_result("", wrap(" {% capture foo %} whatever {% endcapture %} "))
|
62
|
-
end
|
63
|
-
|
64
|
-
def test_nested_blocks_are_blank_but_only_if_all_children_are
|
65
|
-
assert_template_result("", wrap(wrap(" ")))
|
66
|
-
assert_template_result("\n but this is not " * (N + 1),
|
67
|
-
wrap('{% if true %} {% comment %} this is blank {% endcomment %} {% endif %}
|
68
|
-
{% if true %} but this is not {% endif %}'))
|
69
|
-
end
|
70
|
-
|
71
|
-
def test_assigns_are_blank
|
72
|
-
assert_template_result("", wrap(' {% assign foo = "bar" %} '))
|
73
|
-
end
|
74
|
-
|
75
|
-
def test_whitespace_is_blank
|
76
|
-
assert_template_result("", wrap(" "))
|
77
|
-
assert_template_result("", wrap("\t"))
|
78
|
-
end
|
79
|
-
|
80
|
-
def test_whitespace_is_not_blank_if_other_stuff_is_present
|
81
|
-
body = " x "
|
82
|
-
assert_template_result(body * (N + 1), wrap(body))
|
83
|
-
end
|
84
|
-
|
85
|
-
def test_increment_is_not_blank
|
86
|
-
assert_template_result(" 0" * 2 * (N + 1), wrap("{% assign foo = 0 %} {% increment foo %} {% decrement foo %}"))
|
87
|
-
end
|
88
|
-
|
89
|
-
def test_cycle_is_not_blank
|
90
|
-
assert_template_result(" " * ((N + 1) / 2) + " ", wrap("{% cycle ' ', ' ' %}"))
|
91
|
-
end
|
92
|
-
|
93
|
-
def test_raw_is_not_blank
|
94
|
-
assert_template_result(" " * (N + 1), wrap(" {% raw %} {% endraw %}"))
|
95
|
-
end
|
96
|
-
|
97
|
-
def test_include_is_blank
|
98
|
-
Liquid::Template.file_system = BlankTestFileSystem.new
|
99
|
-
assert_template_result("foobar" * (N + 1), wrap("{% include 'foobar' %}"))
|
100
|
-
assert_template_result(" foobar " * (N + 1), wrap("{% include ' foobar ' %}"))
|
101
|
-
assert_template_result(" " * (N + 1), wrap(" {% include ' ' %} "))
|
102
|
-
end
|
103
|
-
|
104
|
-
def test_case_is_blank
|
105
|
-
assert_template_result("", wrap(" {% assign foo = 'bar' %} {% case foo %} {% when 'bar' %} {% when 'whatever' %} {% else %} {% endcase %} "))
|
106
|
-
assert_template_result("", wrap(" {% assign foo = 'else' %} {% case foo %} {% when 'bar' %} {% when 'whatever' %} {% else %} {% endcase %} "))
|
107
|
-
assert_template_result(" x " * (N + 1), wrap(" {% assign foo = 'else' %} {% case foo %} {% when 'bar' %} {% when 'whatever' %} {% else %} x {% endcase %} "))
|
108
|
-
end
|
109
|
-
end
|
@@ -1,58 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'test_helper'
|
4
|
-
|
5
|
-
class BlockTest < Minitest::Test
|
6
|
-
include Liquid
|
7
|
-
|
8
|
-
def test_unexpected_end_tag
|
9
|
-
exc = assert_raises(SyntaxError) do
|
10
|
-
Template.parse("{% if true %}{% endunless %}")
|
11
|
-
end
|
12
|
-
assert_equal(exc.message, "Liquid syntax error: 'endunless' is not a valid delimiter for if tags. use endif")
|
13
|
-
end
|
14
|
-
|
15
|
-
def test_with_custom_tag
|
16
|
-
with_custom_tag('testtag', Block) do
|
17
|
-
assert(Liquid::Template.parse("{% testtag %} {% endtesttag %}"))
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
def test_custom_block_tags_have_a_default_render_to_output_buffer_method_for_backwards_compatibility
|
22
|
-
klass1 = Class.new(Block) do
|
23
|
-
def render(*)
|
24
|
-
'hello'
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
with_custom_tag('blabla', klass1) do
|
29
|
-
template = Liquid::Template.parse("{% blabla %} bla {% endblabla %}")
|
30
|
-
|
31
|
-
assert_equal('hello', template.render)
|
32
|
-
|
33
|
-
buf = +''
|
34
|
-
output = template.render({}, output: buf)
|
35
|
-
assert_equal('hello', output)
|
36
|
-
assert_equal('hello', buf)
|
37
|
-
assert_equal(buf.object_id, output.object_id)
|
38
|
-
end
|
39
|
-
|
40
|
-
klass2 = Class.new(klass1) do
|
41
|
-
def render(*)
|
42
|
-
'foo' + super + 'bar'
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
with_custom_tag('blabla', klass2) do
|
47
|
-
template = Liquid::Template.parse("{% blabla %} foo {% endblabla %}")
|
48
|
-
|
49
|
-
assert_equal('foohellobar', template.render)
|
50
|
-
|
51
|
-
buf = +''
|
52
|
-
output = template.render({}, output: buf)
|
53
|
-
assert_equal('foohellobar', output)
|
54
|
-
assert_equal('foohellobar', buf)
|
55
|
-
assert_equal(buf.object_id, output.object_id)
|
56
|
-
end
|
57
|
-
end
|
58
|
-
end
|
@@ -1,58 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'test_helper'
|
4
|
-
|
5
|
-
class CaptureTest < Minitest::Test
|
6
|
-
include Liquid
|
7
|
-
|
8
|
-
def test_captures_block_content_in_variable
|
9
|
-
assert_template_result("test string", "{% capture 'var' %}test string{% endcapture %}{{var}}", {})
|
10
|
-
end
|
11
|
-
|
12
|
-
def test_capture_with_hyphen_in_variable_name
|
13
|
-
template_source = <<-END_TEMPLATE
|
14
|
-
{% capture this-thing %}Print this-thing{% endcapture %}
|
15
|
-
{{ this-thing }}
|
16
|
-
END_TEMPLATE
|
17
|
-
template = Template.parse(template_source)
|
18
|
-
rendered = template.render!
|
19
|
-
assert_equal("Print this-thing", rendered.strip)
|
20
|
-
end
|
21
|
-
|
22
|
-
def test_capture_to_variable_from_outer_scope_if_existing
|
23
|
-
template_source = <<-END_TEMPLATE
|
24
|
-
{% assign var = '' %}
|
25
|
-
{% if true %}
|
26
|
-
{% capture var %}first-block-string{% endcapture %}
|
27
|
-
{% endif %}
|
28
|
-
{% if true %}
|
29
|
-
{% capture var %}test-string{% endcapture %}
|
30
|
-
{% endif %}
|
31
|
-
{{var}}
|
32
|
-
END_TEMPLATE
|
33
|
-
template = Template.parse(template_source)
|
34
|
-
rendered = template.render!
|
35
|
-
assert_equal("test-string", rendered.gsub(/\s/, ''))
|
36
|
-
end
|
37
|
-
|
38
|
-
def test_assigning_from_capture
|
39
|
-
template_source = <<-END_TEMPLATE
|
40
|
-
{% assign first = '' %}
|
41
|
-
{% assign second = '' %}
|
42
|
-
{% for number in (1..3) %}
|
43
|
-
{% capture first %}{{number}}{% endcapture %}
|
44
|
-
{% assign second = first %}
|
45
|
-
{% endfor %}
|
46
|
-
{{ first }}-{{ second }}
|
47
|
-
END_TEMPLATE
|
48
|
-
template = Template.parse(template_source)
|
49
|
-
rendered = template.render!
|
50
|
-
assert_equal("3-3", rendered.gsub(/\s/, ''))
|
51
|
-
end
|
52
|
-
|
53
|
-
def test_increment_assign_score_by_bytes_not_characters
|
54
|
-
t = Template.parse("{% capture foo %}すごい{% endcapture %}")
|
55
|
-
t.render!
|
56
|
-
assert_equal(9, t.resource_limits.assign_score)
|
57
|
-
end
|
58
|
-
end
|