liquid 4.0.4 → 5.0.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 +32 -4
- data/README.md +6 -0
- data/lib/liquid/block.rb +31 -14
- data/lib/liquid/block_body.rb +164 -54
- data/lib/liquid/condition.rb +39 -18
- data/lib/liquid/context.rb +106 -51
- data/lib/liquid/document.rb +47 -9
- data/lib/liquid/drop.rb +4 -2
- data/lib/liquid/errors.rb +20 -18
- data/lib/liquid/expression.rb +29 -34
- data/lib/liquid/extensions.rb +2 -0
- data/lib/liquid/file_system.rb +6 -4
- data/lib/liquid/forloop_drop.rb +11 -4
- data/lib/liquid/i18n.rb +5 -3
- data/lib/liquid/interrupts.rb +3 -1
- data/lib/liquid/lexer.rb +30 -23
- data/lib/liquid/locales/en.yml +3 -1
- data/lib/liquid/parse_context.rb +16 -4
- data/lib/liquid/parse_tree_visitor.rb +2 -2
- data/lib/liquid/parser.rb +30 -18
- data/lib/liquid/parser_switching.rb +17 -3
- data/lib/liquid/partial_cache.rb +24 -0
- data/lib/liquid/profiler/hooks.rb +26 -14
- data/lib/liquid/profiler.rb +67 -86
- data/lib/liquid/range_lookup.rb +5 -3
- data/lib/liquid/register.rb +6 -0
- data/lib/liquid/resource_limits.rb +47 -8
- data/lib/liquid/standardfilters.rb +62 -43
- data/lib/liquid/static_registers.rb +44 -0
- data/lib/liquid/strainer_factory.rb +36 -0
- data/lib/liquid/strainer_template.rb +53 -0
- data/lib/liquid/tablerowloop_drop.rb +6 -4
- data/lib/liquid/tag/disableable.rb +22 -0
- data/lib/liquid/tag/disabler.rb +21 -0
- data/lib/liquid/tag.rb +28 -6
- data/lib/liquid/tags/assign.rb +24 -10
- data/lib/liquid/tags/break.rb +8 -3
- data/lib/liquid/tags/capture.rb +11 -8
- data/lib/liquid/tags/case.rb +33 -27
- data/lib/liquid/tags/comment.rb +5 -3
- data/lib/liquid/tags/continue.rb +8 -3
- data/lib/liquid/tags/cycle.rb +25 -14
- data/lib/liquid/tags/decrement.rb +6 -3
- data/lib/liquid/tags/echo.rb +26 -0
- data/lib/liquid/tags/for.rb +68 -44
- data/lib/liquid/tags/if.rb +35 -23
- data/lib/liquid/tags/ifchanged.rb +11 -10
- data/lib/liquid/tags/include.rb +34 -47
- data/lib/liquid/tags/increment.rb +7 -3
- data/lib/liquid/tags/raw.rb +14 -11
- data/lib/liquid/tags/render.rb +84 -0
- data/lib/liquid/tags/table_row.rb +23 -19
- data/lib/liquid/tags/unless.rb +15 -15
- data/lib/liquid/template.rb +55 -69
- data/lib/liquid/template_factory.rb +9 -0
- data/lib/liquid/tokenizer.rb +17 -9
- data/lib/liquid/usage.rb +8 -0
- data/lib/liquid/utils.rb +5 -3
- data/lib/liquid/variable.rb +47 -19
- data/lib/liquid/variable_lookup.rb +8 -6
- data/lib/liquid/version.rb +2 -1
- data/lib/liquid.rb +17 -5
- data/test/integration/assign_test.rb +74 -5
- data/test/integration/blank_test.rb +11 -8
- data/test/integration/block_test.rb +47 -1
- data/test/integration/capture_test.rb +18 -10
- data/test/integration/context_test.rb +608 -5
- data/test/integration/document_test.rb +4 -2
- data/test/integration/drop_test.rb +67 -57
- data/test/integration/error_handling_test.rb +73 -61
- data/test/integration/expression_test.rb +46 -0
- data/test/integration/filter_test.rb +53 -42
- data/test/integration/hash_ordering_test.rb +5 -3
- data/test/integration/output_test.rb +26 -24
- data/test/integration/parsing_quirks_test.rb +19 -7
- data/test/integration/{render_profiling_test.rb → profiler_test.rb} +84 -25
- data/test/integration/security_test.rb +30 -21
- data/test/integration/standard_filter_test.rb +339 -281
- data/test/integration/tag/disableable_test.rb +59 -0
- data/test/integration/tag_test.rb +45 -0
- data/test/integration/tags/break_tag_test.rb +4 -2
- data/test/integration/tags/continue_tag_test.rb +4 -2
- data/test/integration/tags/echo_test.rb +13 -0
- data/test/integration/tags/for_tag_test.rb +107 -51
- data/test/integration/tags/if_else_tag_test.rb +5 -3
- data/test/integration/tags/include_tag_test.rb +70 -54
- data/test/integration/tags/increment_tag_test.rb +4 -2
- data/test/integration/tags/liquid_tag_test.rb +116 -0
- data/test/integration/tags/raw_tag_test.rb +14 -11
- data/test/integration/tags/render_tag_test.rb +213 -0
- data/test/integration/tags/standard_tag_test.rb +38 -31
- data/test/integration/tags/statements_test.rb +23 -21
- data/test/integration/tags/table_row_test.rb +2 -0
- data/test/integration/tags/unless_else_tag_test.rb +4 -2
- data/test/integration/template_test.rb +118 -124
- data/test/integration/trim_mode_test.rb +78 -44
- data/test/integration/variable_test.rb +43 -32
- data/test/test_helper.rb +75 -14
- data/test/unit/block_unit_test.rb +19 -24
- data/test/unit/condition_unit_test.rb +79 -77
- data/test/unit/file_system_unit_test.rb +6 -4
- data/test/unit/i18n_unit_test.rb +7 -5
- data/test/unit/lexer_unit_test.rb +11 -9
- data/test/{integration → unit}/parse_tree_visitor_test.rb +1 -1
- data/test/unit/parser_unit_test.rb +37 -35
- data/test/unit/partial_cache_unit_test.rb +128 -0
- data/test/unit/regexp_unit_test.rb +17 -15
- data/test/unit/static_registers_unit_test.rb +156 -0
- data/test/unit/strainer_factory_unit_test.rb +100 -0
- data/test/unit/strainer_template_unit_test.rb +82 -0
- data/test/unit/tag_unit_test.rb +5 -3
- data/test/unit/tags/case_tag_unit_test.rb +3 -1
- data/test/unit/tags/for_tag_unit_test.rb +4 -2
- data/test/unit/tags/if_tag_unit_test.rb +3 -1
- data/test/unit/template_factory_unit_test.rb +12 -0
- data/test/unit/template_unit_test.rb +19 -10
- data/test/unit/tokenizer_unit_test.rb +19 -17
- data/test/unit/variable_unit_test.rb +51 -49
- metadata +75 -47
- data/lib/liquid/strainer.rb +0 -66
- data/test/unit/context_unit_test.rb +0 -490
- data/test/unit/strainer_unit_test.rb +0 -164
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'test_helper'
|
2
4
|
|
3
5
|
class StandardTagTest < Minitest::Test
|
@@ -69,7 +71,7 @@ class StandardTagTest < Minitest::Test
|
|
69
71
|
assert_raises(SyntaxError) do
|
70
72
|
assert_template_result('content foo content foo ',
|
71
73
|
'{{ var2 }}{% capture %}{{ var }} foo {% endcapture %}{{ var2 }}{{ var2 }}',
|
72
|
-
|
74
|
+
'var' => 'content')
|
73
75
|
end
|
74
76
|
end
|
75
77
|
|
@@ -172,47 +174,52 @@ class StandardTagTest < Minitest::Test
|
|
172
174
|
|
173
175
|
def test_assign_from_case
|
174
176
|
# Example from the shopify forums
|
175
|
-
code
|
177
|
+
code = "{% case collection.handle %}{% when 'menswear-jackets' %}{% assign ptitle = 'menswear' %}{% when 'menswear-t-shirts' %}{% assign ptitle = 'menswear' %}{% else %}{% assign ptitle = 'womenswear' %}{% endcase %}{{ ptitle }}"
|
176
178
|
template = Liquid::Template.parse(code)
|
177
|
-
assert_equal
|
178
|
-
assert_equal
|
179
|
-
assert_equal
|
180
|
-
assert_equal
|
181
|
-
assert_equal
|
179
|
+
assert_equal("menswear", template.render!("collection" => { 'handle' => 'menswear-jackets' }))
|
180
|
+
assert_equal("menswear", template.render!("collection" => { 'handle' => 'menswear-t-shirts' }))
|
181
|
+
assert_equal("womenswear", template.render!("collection" => { 'handle' => 'x' }))
|
182
|
+
assert_equal("womenswear", template.render!("collection" => { 'handle' => 'y' }))
|
183
|
+
assert_equal("womenswear", template.render!("collection" => { 'handle' => 'z' }))
|
182
184
|
end
|
183
185
|
|
184
186
|
def test_case_when_or
|
185
187
|
code = '{% case condition %}{% when 1 or 2 or 3 %} its 1 or 2 or 3 {% when 4 %} its 4 {% endcase %}'
|
186
|
-
assert_template_result(' its 1 or 2 or 3 ', code,
|
187
|
-
assert_template_result(' its 1 or 2 or 3 ', code,
|
188
|
-
assert_template_result(' its 1 or 2 or 3 ', code,
|
189
|
-
assert_template_result(' its 4 ', code,
|
190
|
-
assert_template_result('', code,
|
188
|
+
assert_template_result(' its 1 or 2 or 3 ', code, 'condition' => 1)
|
189
|
+
assert_template_result(' its 1 or 2 or 3 ', code, 'condition' => 2)
|
190
|
+
assert_template_result(' its 1 or 2 or 3 ', code, 'condition' => 3)
|
191
|
+
assert_template_result(' its 4 ', code, 'condition' => 4)
|
192
|
+
assert_template_result('', code, 'condition' => 5)
|
191
193
|
|
192
194
|
code = '{% case condition %}{% when 1 or "string" or null %} its 1 or 2 or 3 {% when 4 %} its 4 {% endcase %}'
|
193
|
-
assert_template_result(' its 1 or 2 or 3 ', code,
|
194
|
-
assert_template_result(' its 1 or 2 or 3 ', code,
|
195
|
-
assert_template_result(' its 1 or 2 or 3 ', code,
|
196
|
-
assert_template_result('', code,
|
195
|
+
assert_template_result(' its 1 or 2 or 3 ', code, 'condition' => 1)
|
196
|
+
assert_template_result(' its 1 or 2 or 3 ', code, 'condition' => 'string')
|
197
|
+
assert_template_result(' its 1 or 2 or 3 ', code, 'condition' => nil)
|
198
|
+
assert_template_result('', code, 'condition' => 'something else')
|
197
199
|
end
|
198
200
|
|
199
201
|
def test_case_when_comma
|
200
202
|
code = '{% case condition %}{% when 1, 2, 3 %} its 1 or 2 or 3 {% when 4 %} its 4 {% endcase %}'
|
201
|
-
assert_template_result(' its 1 or 2 or 3 ', code,
|
202
|
-
assert_template_result(' its 1 or 2 or 3 ', code,
|
203
|
-
assert_template_result(' its 1 or 2 or 3 ', code,
|
204
|
-
assert_template_result(' its 4 ', code,
|
205
|
-
assert_template_result('', code,
|
203
|
+
assert_template_result(' its 1 or 2 or 3 ', code, 'condition' => 1)
|
204
|
+
assert_template_result(' its 1 or 2 or 3 ', code, 'condition' => 2)
|
205
|
+
assert_template_result(' its 1 or 2 or 3 ', code, 'condition' => 3)
|
206
|
+
assert_template_result(' its 4 ', code, 'condition' => 4)
|
207
|
+
assert_template_result('', code, 'condition' => 5)
|
206
208
|
|
207
209
|
code = '{% case condition %}{% when 1, "string", null %} its 1 or 2 or 3 {% when 4 %} its 4 {% endcase %}'
|
208
|
-
assert_template_result(' its 1 or 2 or 3 ', code,
|
209
|
-
assert_template_result(' its 1 or 2 or 3 ', code,
|
210
|
-
assert_template_result(' its 1 or 2 or 3 ', code,
|
211
|
-
assert_template_result('', code,
|
210
|
+
assert_template_result(' its 1 or 2 or 3 ', code, 'condition' => 1)
|
211
|
+
assert_template_result(' its 1 or 2 or 3 ', code, 'condition' => 'string')
|
212
|
+
assert_template_result(' its 1 or 2 or 3 ', code, 'condition' => nil)
|
213
|
+
assert_template_result('', code, 'condition' => 'something else')
|
214
|
+
end
|
215
|
+
|
216
|
+
def test_case_when_comma_and_blank_body
|
217
|
+
code = '{% case condition %}{% when 1, 2 %} {% assign r = "result" %} {% endcase %}{{ r }}'
|
218
|
+
assert_template_result('result', code, 'condition' => 2)
|
212
219
|
end
|
213
220
|
|
214
221
|
def test_assign
|
215
|
-
assert_template_result
|
222
|
+
assert_template_result('variable', '{% assign a = "variable"%}{{a}}')
|
216
223
|
end
|
217
224
|
|
218
225
|
def test_assign_unassigned
|
@@ -221,11 +228,11 @@ class StandardTagTest < Minitest::Test
|
|
221
228
|
end
|
222
229
|
|
223
230
|
def test_assign_an_empty_string
|
224
|
-
assert_template_result
|
231
|
+
assert_template_result('', '{% assign a = ""%}{{a}}')
|
225
232
|
end
|
226
233
|
|
227
234
|
def test_assign_is_global
|
228
|
-
assert_template_result
|
235
|
+
assert_template_result('variable', '{%for i in (1..2) %}{% assign a = "variable"%}{% endfor %}{{a}}')
|
229
236
|
end
|
230
237
|
|
231
238
|
def test_case_detects_bad_syntax
|
@@ -283,14 +290,14 @@ class StandardTagTest < Minitest::Test
|
|
283
290
|
end
|
284
291
|
|
285
292
|
def test_ifchanged
|
286
|
-
assigns = { 'array' => [
|
293
|
+
assigns = { 'array' => [1, 1, 2, 2, 3, 3] }
|
287
294
|
assert_template_result('123', '{%for item in array%}{%ifchanged%}{{item}}{% endifchanged %}{%endfor%}', assigns)
|
288
295
|
|
289
|
-
assigns = { 'array' => [
|
296
|
+
assigns = { 'array' => [1, 1, 1, 1] }
|
290
297
|
assert_template_result('1', '{%for item in array%}{%ifchanged%}{{item}}{% endifchanged %}{%endfor%}', assigns)
|
291
298
|
end
|
292
299
|
|
293
300
|
def test_multiline_tag
|
294
|
-
assert_template_result
|
301
|
+
assert_template_result('0 1 2 3', "0{%\nfor i in (1..3)\n%} {{\ni\n}}{%\nendfor\n%}")
|
295
302
|
end
|
296
303
|
end # StandardTagTest
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'test_helper'
|
2
4
|
|
3
5
|
class StatementsTest < Minitest::Test
|
@@ -5,75 +7,75 @@ class StatementsTest < Minitest::Test
|
|
5
7
|
|
6
8
|
def test_true_eql_true
|
7
9
|
text = ' {% if true == true %} true {% else %} false {% endif %} '
|
8
|
-
assert_template_result
|
10
|
+
assert_template_result(' true ', text)
|
9
11
|
end
|
10
12
|
|
11
13
|
def test_true_not_eql_true
|
12
14
|
text = ' {% if true != true %} true {% else %} false {% endif %} '
|
13
|
-
assert_template_result
|
15
|
+
assert_template_result(' false ', text)
|
14
16
|
end
|
15
17
|
|
16
18
|
def test_true_lq_true
|
17
19
|
text = ' {% if 0 > 0 %} true {% else %} false {% endif %} '
|
18
|
-
assert_template_result
|
20
|
+
assert_template_result(' false ', text)
|
19
21
|
end
|
20
22
|
|
21
23
|
def test_one_lq_zero
|
22
24
|
text = ' {% if 1 > 0 %} true {% else %} false {% endif %} '
|
23
|
-
assert_template_result
|
25
|
+
assert_template_result(' true ', text)
|
24
26
|
end
|
25
27
|
|
26
28
|
def test_zero_lq_one
|
27
29
|
text = ' {% if 0 < 1 %} true {% else %} false {% endif %} '
|
28
|
-
assert_template_result
|
30
|
+
assert_template_result(' true ', text)
|
29
31
|
end
|
30
32
|
|
31
33
|
def test_zero_lq_or_equal_one
|
32
34
|
text = ' {% if 0 <= 0 %} true {% else %} false {% endif %} '
|
33
|
-
assert_template_result
|
35
|
+
assert_template_result(' true ', text)
|
34
36
|
end
|
35
37
|
|
36
38
|
def test_zero_lq_or_equal_one_involving_nil
|
37
39
|
text = ' {% if null <= 0 %} true {% else %} false {% endif %} '
|
38
|
-
assert_template_result
|
40
|
+
assert_template_result(' false ', text)
|
39
41
|
|
40
42
|
text = ' {% if 0 <= null %} true {% else %} false {% endif %} '
|
41
|
-
assert_template_result
|
43
|
+
assert_template_result(' false ', text)
|
42
44
|
end
|
43
45
|
|
44
46
|
def test_zero_lqq_or_equal_one
|
45
47
|
text = ' {% if 0 >= 0 %} true {% else %} false {% endif %} '
|
46
|
-
assert_template_result
|
48
|
+
assert_template_result(' true ', text)
|
47
49
|
end
|
48
50
|
|
49
51
|
def test_strings
|
50
52
|
text = " {% if 'test' == 'test' %} true {% else %} false {% endif %} "
|
51
|
-
assert_template_result
|
53
|
+
assert_template_result(' true ', text)
|
52
54
|
end
|
53
55
|
|
54
56
|
def test_strings_not_equal
|
55
57
|
text = " {% if 'test' != 'test' %} true {% else %} false {% endif %} "
|
56
|
-
assert_template_result
|
58
|
+
assert_template_result(' false ', text)
|
57
59
|
end
|
58
60
|
|
59
61
|
def test_var_strings_equal
|
60
62
|
text = ' {% if var == "hello there!" %} true {% else %} false {% endif %} '
|
61
|
-
assert_template_result
|
63
|
+
assert_template_result(' true ', text, 'var' => 'hello there!')
|
62
64
|
end
|
63
65
|
|
64
66
|
def test_var_strings_are_not_equal
|
65
67
|
text = ' {% if "hello there!" == var %} true {% else %} false {% endif %} '
|
66
|
-
assert_template_result
|
68
|
+
assert_template_result(' true ', text, 'var' => 'hello there!')
|
67
69
|
end
|
68
70
|
|
69
71
|
def test_var_and_long_string_are_equal
|
70
72
|
text = " {% if var == 'hello there!' %} true {% else %} false {% endif %} "
|
71
|
-
assert_template_result
|
73
|
+
assert_template_result(' true ', text, 'var' => 'hello there!')
|
72
74
|
end
|
73
75
|
|
74
76
|
def test_var_and_long_string_are_equal_backwards
|
75
77
|
text = " {% if 'hello there!' == var %} true {% else %} false {% endif %} "
|
76
|
-
assert_template_result
|
78
|
+
assert_template_result(' true ', text, 'var' => 'hello there!')
|
77
79
|
end
|
78
80
|
|
79
81
|
# def test_is_nil
|
@@ -85,27 +87,27 @@ class StatementsTest < Minitest::Test
|
|
85
87
|
|
86
88
|
def test_is_collection_empty
|
87
89
|
text = ' {% if array == empty %} true {% else %} false {% endif %} '
|
88
|
-
assert_template_result
|
90
|
+
assert_template_result(' true ', text, 'array' => [])
|
89
91
|
end
|
90
92
|
|
91
93
|
def test_is_not_collection_empty
|
92
94
|
text = ' {% if array == empty %} true {% else %} false {% endif %} '
|
93
|
-
assert_template_result
|
95
|
+
assert_template_result(' false ', text, 'array' => [1, 2, 3])
|
94
96
|
end
|
95
97
|
|
96
98
|
def test_nil
|
97
99
|
text = ' {% if var == nil %} true {% else %} false {% endif %} '
|
98
|
-
assert_template_result
|
100
|
+
assert_template_result(' true ', text, 'var' => nil)
|
99
101
|
|
100
102
|
text = ' {% if var == null %} true {% else %} false {% endif %} '
|
101
|
-
assert_template_result
|
103
|
+
assert_template_result(' true ', text, 'var' => nil)
|
102
104
|
end
|
103
105
|
|
104
106
|
def test_not_nil
|
105
107
|
text = ' {% if var != nil %} true {% else %} false {% endif %} '
|
106
|
-
assert_template_result
|
108
|
+
assert_template_result(' true ', text, 'var' => 1)
|
107
109
|
|
108
110
|
text = ' {% if var != null %} true {% else %} false {% endif %} '
|
109
|
-
assert_template_result
|
111
|
+
assert_template_result(' true ', text, 'var' => 1)
|
110
112
|
end
|
111
113
|
end # StatementsTest
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'test_helper'
|
2
4
|
|
3
5
|
class UnlessElseTagTest < Minitest::Test
|
@@ -17,10 +19,10 @@ class UnlessElseTagTest < Minitest::Test
|
|
17
19
|
end
|
18
20
|
|
19
21
|
def test_unless_in_loop
|
20
|
-
assert_template_result
|
22
|
+
assert_template_result('23', '{% for i in choices %}{% unless i %}{{ forloop.index }}{% endunless %}{% endfor %}', 'choices' => [1, nil, false])
|
21
23
|
end
|
22
24
|
|
23
25
|
def test_unless_else_in_loop
|
24
|
-
assert_template_result
|
26
|
+
assert_template_result(' TRUE 2 3 ', '{% for i in choices %}{% unless i %} {{ forloop.index }} {% else %} TRUE {% endunless %}{% endfor %}', 'choices' => [1, nil, false])
|
25
27
|
end
|
26
28
|
end # UnlessElseTest
|