liquid 5.3.0 → 5.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (106) hide show
  1. checksums.yaml +4 -4
  2. data/History.md +20 -1
  3. data/README.md +5 -5
  4. data/lib/liquid/block.rb +8 -4
  5. data/lib/liquid/block_body.rb +21 -6
  6. data/lib/liquid/condition.rb +9 -4
  7. data/lib/liquid/context.rb +13 -5
  8. data/lib/liquid/drop.rb +4 -0
  9. data/lib/liquid/errors.rb +16 -15
  10. data/lib/liquid/expression.rb +4 -1
  11. data/lib/liquid/forloop_drop.rb +45 -5
  12. data/lib/liquid/lexer.rb +2 -3
  13. data/lib/liquid/locales/en.yml +7 -5
  14. data/lib/liquid/partial_cache.rb +15 -6
  15. data/lib/liquid/range_lookup.rb +11 -1
  16. data/lib/liquid/{static_registers.rb → registers.rb} +13 -10
  17. data/lib/liquid/standardfilters.rb +480 -68
  18. data/lib/liquid/strainer_factory.rb +4 -0
  19. data/lib/liquid/strainer_template.rb +4 -0
  20. data/lib/liquid/tablerowloop_drop.rb +58 -1
  21. data/lib/liquid/tag/disabler.rb +0 -8
  22. data/lib/liquid/tag.rb +10 -3
  23. data/lib/liquid/tags/assign.rb +12 -8
  24. data/lib/liquid/tags/break.rb +8 -0
  25. data/lib/liquid/tags/capture.rb +13 -10
  26. data/lib/liquid/tags/case.rb +22 -1
  27. data/lib/liquid/tags/comment.rb +72 -0
  28. data/lib/liquid/tags/continue.rb +8 -9
  29. data/lib/liquid/tags/cycle.rb +12 -11
  30. data/lib/liquid/tags/decrement.rb +22 -20
  31. data/lib/liquid/tags/echo.rb +16 -9
  32. data/lib/liquid/tags/for.rb +25 -46
  33. data/lib/liquid/tags/if.rb +12 -10
  34. data/lib/liquid/tags/include.rb +21 -17
  35. data/lib/liquid/tags/increment.rb +22 -17
  36. data/lib/liquid/tags/inline_comment.rb +30 -0
  37. data/lib/liquid/tags/raw.rb +13 -2
  38. data/lib/liquid/tags/render.rb +37 -8
  39. data/lib/liquid/tags/table_row.rb +33 -3
  40. data/lib/liquid/tags/unless.rb +17 -6
  41. data/lib/liquid/template.rb +11 -4
  42. data/lib/liquid/tokenizer.rb +9 -3
  43. data/lib/liquid/variable.rb +4 -4
  44. data/lib/liquid/variable_lookup.rb +10 -7
  45. data/lib/liquid/version.rb +1 -1
  46. data/lib/liquid.rb +3 -3
  47. metadata +7 -123
  48. data/lib/liquid/register.rb +0 -6
  49. data/test/fixtures/en_locale.yml +0 -9
  50. data/test/integration/assign_test.rb +0 -117
  51. data/test/integration/blank_test.rb +0 -109
  52. data/test/integration/block_test.rb +0 -58
  53. data/test/integration/capture_test.rb +0 -58
  54. data/test/integration/context_test.rb +0 -634
  55. data/test/integration/document_test.rb +0 -21
  56. data/test/integration/drop_test.rb +0 -257
  57. data/test/integration/error_handling_test.rb +0 -272
  58. data/test/integration/expression_test.rb +0 -46
  59. data/test/integration/filter_kwarg_test.rb +0 -24
  60. data/test/integration/filter_test.rb +0 -189
  61. data/test/integration/hash_ordering_test.rb +0 -25
  62. data/test/integration/output_test.rb +0 -125
  63. data/test/integration/parsing_quirks_test.rb +0 -134
  64. data/test/integration/profiler_test.rb +0 -240
  65. data/test/integration/security_test.rb +0 -89
  66. data/test/integration/standard_filter_test.rb +0 -925
  67. data/test/integration/tag/disableable_test.rb +0 -59
  68. data/test/integration/tag_test.rb +0 -45
  69. data/test/integration/tags/break_tag_test.rb +0 -17
  70. data/test/integration/tags/continue_tag_test.rb +0 -17
  71. data/test/integration/tags/echo_test.rb +0 -13
  72. data/test/integration/tags/for_tag_test.rb +0 -466
  73. data/test/integration/tags/if_else_tag_test.rb +0 -190
  74. data/test/integration/tags/include_tag_test.rb +0 -269
  75. data/test/integration/tags/increment_tag_test.rb +0 -25
  76. data/test/integration/tags/liquid_tag_test.rb +0 -116
  77. data/test/integration/tags/raw_tag_test.rb +0 -34
  78. data/test/integration/tags/render_tag_test.rb +0 -213
  79. data/test/integration/tags/standard_tag_test.rb +0 -303
  80. data/test/integration/tags/statements_test.rb +0 -113
  81. data/test/integration/tags/table_row_test.rb +0 -66
  82. data/test/integration/tags/unless_else_tag_test.rb +0 -28
  83. data/test/integration/template_test.rb +0 -340
  84. data/test/integration/trim_mode_test.rb +0 -563
  85. data/test/integration/variable_test.rb +0 -138
  86. data/test/test_helper.rb +0 -207
  87. data/test/unit/block_unit_test.rb +0 -53
  88. data/test/unit/condition_unit_test.rb +0 -181
  89. data/test/unit/file_system_unit_test.rb +0 -37
  90. data/test/unit/i18n_unit_test.rb +0 -39
  91. data/test/unit/lexer_unit_test.rb +0 -53
  92. data/test/unit/parse_tree_visitor_test.rb +0 -261
  93. data/test/unit/parser_unit_test.rb +0 -84
  94. data/test/unit/partial_cache_unit_test.rb +0 -128
  95. data/test/unit/regexp_unit_test.rb +0 -46
  96. data/test/unit/static_registers_unit_test.rb +0 -156
  97. data/test/unit/strainer_factory_unit_test.rb +0 -101
  98. data/test/unit/strainer_template_unit_test.rb +0 -82
  99. data/test/unit/tag_unit_test.rb +0 -23
  100. data/test/unit/tags/case_tag_unit_test.rb +0 -12
  101. data/test/unit/tags/for_tag_unit_test.rb +0 -15
  102. data/test/unit/tags/if_tag_unit_test.rb +0 -10
  103. data/test/unit/template_factory_unit_test.rb +0 -12
  104. data/test/unit/template_unit_test.rb +0 -87
  105. data/test/unit/tokenizer_unit_test.rb +0 -62
  106. data/test/unit/variable_unit_test.rb +0 -164
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: liquid
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.3.0
4
+ version: 5.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tobias Lütke
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-03-22 00:00:00.000000000 Z
11
+ date: 2024-03-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -74,10 +74,9 @@ files:
74
74
  - lib/liquid/profiler.rb
75
75
  - lib/liquid/profiler/hooks.rb
76
76
  - lib/liquid/range_lookup.rb
77
- - lib/liquid/register.rb
77
+ - lib/liquid/registers.rb
78
78
  - lib/liquid/resource_limits.rb
79
79
  - lib/liquid/standardfilters.rb
80
- - lib/liquid/static_registers.rb
81
80
  - lib/liquid/strainer_factory.rb
82
81
  - lib/liquid/strainer_template.rb
83
82
  - lib/liquid/tablerowloop_drop.rb
@@ -98,6 +97,7 @@ files:
98
97
  - lib/liquid/tags/ifchanged.rb
99
98
  - lib/liquid/tags/include.rb
100
99
  - lib/liquid/tags/increment.rb
100
+ - lib/liquid/tags/inline_comment.rb
101
101
  - lib/liquid/tags/raw.rb
102
102
  - lib/liquid/tags/render.rb
103
103
  - lib/liquid/tags/table_row.rb
@@ -110,64 +110,6 @@ files:
110
110
  - lib/liquid/variable.rb
111
111
  - lib/liquid/variable_lookup.rb
112
112
  - lib/liquid/version.rb
113
- - test/fixtures/en_locale.yml
114
- - test/integration/assign_test.rb
115
- - test/integration/blank_test.rb
116
- - test/integration/block_test.rb
117
- - test/integration/capture_test.rb
118
- - test/integration/context_test.rb
119
- - test/integration/document_test.rb
120
- - test/integration/drop_test.rb
121
- - test/integration/error_handling_test.rb
122
- - test/integration/expression_test.rb
123
- - test/integration/filter_kwarg_test.rb
124
- - test/integration/filter_test.rb
125
- - test/integration/hash_ordering_test.rb
126
- - test/integration/output_test.rb
127
- - test/integration/parsing_quirks_test.rb
128
- - test/integration/profiler_test.rb
129
- - test/integration/security_test.rb
130
- - test/integration/standard_filter_test.rb
131
- - test/integration/tag/disableable_test.rb
132
- - test/integration/tag_test.rb
133
- - test/integration/tags/break_tag_test.rb
134
- - test/integration/tags/continue_tag_test.rb
135
- - test/integration/tags/echo_test.rb
136
- - test/integration/tags/for_tag_test.rb
137
- - test/integration/tags/if_else_tag_test.rb
138
- - test/integration/tags/include_tag_test.rb
139
- - test/integration/tags/increment_tag_test.rb
140
- - test/integration/tags/liquid_tag_test.rb
141
- - test/integration/tags/raw_tag_test.rb
142
- - test/integration/tags/render_tag_test.rb
143
- - test/integration/tags/standard_tag_test.rb
144
- - test/integration/tags/statements_test.rb
145
- - test/integration/tags/table_row_test.rb
146
- - test/integration/tags/unless_else_tag_test.rb
147
- - test/integration/template_test.rb
148
- - test/integration/trim_mode_test.rb
149
- - test/integration/variable_test.rb
150
- - test/test_helper.rb
151
- - test/unit/block_unit_test.rb
152
- - test/unit/condition_unit_test.rb
153
- - test/unit/file_system_unit_test.rb
154
- - test/unit/i18n_unit_test.rb
155
- - test/unit/lexer_unit_test.rb
156
- - test/unit/parse_tree_visitor_test.rb
157
- - test/unit/parser_unit_test.rb
158
- - test/unit/partial_cache_unit_test.rb
159
- - test/unit/regexp_unit_test.rb
160
- - test/unit/static_registers_unit_test.rb
161
- - test/unit/strainer_factory_unit_test.rb
162
- - test/unit/strainer_template_unit_test.rb
163
- - test/unit/tag_unit_test.rb
164
- - test/unit/tags/case_tag_unit_test.rb
165
- - test/unit/tags/for_tag_unit_test.rb
166
- - test/unit/tags/if_tag_unit_test.rb
167
- - test/unit/template_factory_unit_test.rb
168
- - test/unit/template_unit_test.rb
169
- - test/unit/tokenizer_unit_test.rb
170
- - test/unit/variable_unit_test.rb
171
113
  homepage: http://www.liquidmarkup.org
172
114
  licenses:
173
115
  - MIT
@@ -181,73 +123,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
181
123
  requirements:
182
124
  - - ">="
183
125
  - !ruby/object:Gem::Version
184
- version: 2.5.0
126
+ version: 2.7.0
185
127
  required_rubygems_version: !ruby/object:Gem::Requirement
186
128
  requirements:
187
129
  - - ">="
188
130
  - !ruby/object:Gem::Version
189
131
  version: 1.3.7
190
132
  requirements: []
191
- rubygems_version: 3.2.20
133
+ rubygems_version: 3.5.6
192
134
  signing_key:
193
135
  specification_version: 4
194
136
  summary: A secure, non-evaling end user template engine with aesthetic markup.
195
- test_files:
196
- - test/unit/parser_unit_test.rb
197
- - test/unit/static_registers_unit_test.rb
198
- - test/unit/tag_unit_test.rb
199
- - test/unit/strainer_factory_unit_test.rb
200
- - test/unit/partial_cache_unit_test.rb
201
- - test/unit/strainer_template_unit_test.rb
202
- - test/unit/lexer_unit_test.rb
203
- - test/unit/parse_tree_visitor_test.rb
204
- - test/unit/i18n_unit_test.rb
205
- - test/unit/tokenizer_unit_test.rb
206
- - test/unit/template_factory_unit_test.rb
207
- - test/unit/condition_unit_test.rb
208
- - test/unit/block_unit_test.rb
209
- - test/unit/file_system_unit_test.rb
210
- - test/unit/variable_unit_test.rb
211
- - test/unit/template_unit_test.rb
212
- - test/unit/tags/if_tag_unit_test.rb
213
- - test/unit/tags/case_tag_unit_test.rb
214
- - test/unit/tags/for_tag_unit_test.rb
215
- - test/unit/regexp_unit_test.rb
216
- - test/test_helper.rb
217
- - test/integration/document_test.rb
218
- - test/integration/tag_test.rb
219
- - test/integration/filter_kwarg_test.rb
220
- - test/integration/trim_mode_test.rb
221
- - test/integration/profiler_test.rb
222
- - test/integration/security_test.rb
223
- - test/integration/capture_test.rb
224
- - test/integration/parsing_quirks_test.rb
225
- - test/integration/blank_test.rb
226
- - test/integration/template_test.rb
227
- - test/integration/tag/disableable_test.rb
228
- - test/integration/variable_test.rb
229
- - test/integration/output_test.rb
230
- - test/integration/drop_test.rb
231
- - test/integration/standard_filter_test.rb
232
- - test/integration/expression_test.rb
233
- - test/integration/block_test.rb
234
- - test/integration/hash_ordering_test.rb
235
- - test/integration/filter_test.rb
236
- - test/integration/tags/break_tag_test.rb
237
- - test/integration/tags/standard_tag_test.rb
238
- - test/integration/tags/liquid_tag_test.rb
239
- - test/integration/tags/table_row_test.rb
240
- - test/integration/tags/render_tag_test.rb
241
- - test/integration/tags/include_tag_test.rb
242
- - test/integration/tags/increment_tag_test.rb
243
- - test/integration/tags/if_else_tag_test.rb
244
- - test/integration/tags/continue_tag_test.rb
245
- - test/integration/tags/echo_test.rb
246
- - test/integration/tags/raw_tag_test.rb
247
- - test/integration/tags/for_tag_test.rb
248
- - test/integration/tags/statements_test.rb
249
- - test/integration/tags/unless_else_tag_test.rb
250
- - test/integration/context_test.rb
251
- - test/integration/error_handling_test.rb
252
- - test/integration/assign_test.rb
253
- - test/fixtures/en_locale.yml
137
+ test_files: []
@@ -1,6 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Liquid
4
- class Register
5
- end
6
- end
@@ -1,9 +0,0 @@
1
- ---
2
- simple: "less is more"
3
- whatever: "something %{something}"
4
- errors:
5
- i18n:
6
- undefined_interpolation: "undefined key %{key}"
7
- unknown_translation: "translation '%{name}' wasn't found"
8
- syntax:
9
- oops: "something wasn't right"
@@ -1,117 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'test_helper'
4
-
5
- class AssignTest < Minitest::Test
6
- include Liquid
7
-
8
- def test_assign_with_hyphen_in_variable_name
9
- template_source = <<-END_TEMPLATE
10
- {% assign this-thing = 'Print this-thing' %}
11
- {{ this-thing }}
12
- END_TEMPLATE
13
- template = Template.parse(template_source)
14
- rendered = template.render!
15
- assert_equal("Print this-thing", rendered.strip)
16
- end
17
-
18
- def test_assigned_variable
19
- assert_template_result('.foo.',
20
- '{% assign foo = values %}.{{ foo[0] }}.',
21
- 'values' => %w(foo bar baz))
22
-
23
- assert_template_result('.bar.',
24
- '{% assign foo = values %}.{{ foo[1] }}.',
25
- 'values' => %w(foo bar baz))
26
- end
27
-
28
- def test_assign_with_filter
29
- assert_template_result('.bar.',
30
- '{% assign foo = values | split: "," %}.{{ foo[1] }}.',
31
- 'values' => "foo,bar,baz")
32
- end
33
-
34
- def test_assign_syntax_error
35
- assert_match_syntax_error(/assign/,
36
- '{% assign foo not values %}.',
37
- 'values' => "foo,bar,baz")
38
- end
39
-
40
- def test_assign_uses_error_mode
41
- with_error_mode(:strict) do
42
- assert_raises(SyntaxError) do
43
- Template.parse("{% assign foo = ('X' | downcase) %}")
44
- end
45
- end
46
- with_error_mode(:lax) do
47
- assert(Template.parse("{% assign foo = ('X' | downcase) %}"))
48
- end
49
- end
50
-
51
- def test_expression_with_whitespace_in_square_brackets
52
- source = "{% assign r = a[ 'b' ] %}{{ r }}"
53
- assert_template_result('result', source, 'a' => { 'b' => 'result' })
54
- end
55
-
56
- def test_assign_score_exceeding_resource_limit
57
- t = Template.parse("{% assign foo = 42 %}{% assign bar = 23 %}")
58
- t.resource_limits.assign_score_limit = 1
59
- assert_equal("Liquid error: Memory limits exceeded", t.render)
60
- assert(t.resource_limits.reached?)
61
-
62
- t.resource_limits.assign_score_limit = 2
63
- assert_equal("", t.render!)
64
- refute_nil(t.resource_limits.assign_score)
65
- end
66
-
67
- def test_assign_score_exceeding_limit_from_composite_object
68
- t = Template.parse("{% assign foo = 'aaaa' | reverse %}")
69
-
70
- t.resource_limits.assign_score_limit = 3
71
- assert_equal("Liquid error: Memory limits exceeded", t.render)
72
- assert(t.resource_limits.reached?)
73
-
74
- t.resource_limits.assign_score_limit = 5
75
- assert_equal("", t.render!)
76
- end
77
-
78
- def test_assign_score_of_int
79
- assert_equal(1, assign_score_of(123))
80
- end
81
-
82
- def test_assign_score_of_string_counts_bytes
83
- assert_equal(3, assign_score_of('123'))
84
- assert_equal(5, assign_score_of('12345'))
85
- assert_equal(9, assign_score_of('すごい'))
86
- end
87
-
88
- def test_assign_score_of_array
89
- assert_equal(1, assign_score_of([]))
90
- assert_equal(2, assign_score_of([123]))
91
- assert_equal(6, assign_score_of([123, 'abcd']))
92
- end
93
-
94
- def test_assign_score_of_hash
95
- assert_equal(1, assign_score_of({}))
96
- assert_equal(5, assign_score_of('int' => 123))
97
- assert_equal(12, assign_score_of('int' => 123, 'str' => 'abcd'))
98
- end
99
-
100
- private
101
-
102
- class ObjectWrapperDrop < Liquid::Drop
103
- def initialize(obj)
104
- @obj = obj
105
- end
106
-
107
- def value
108
- @obj
109
- end
110
- end
111
-
112
- def assign_score_of(obj)
113
- context = Liquid::Context.new('drop' => ObjectWrapperDrop.new(obj))
114
- Liquid::Template.parse('{% assign obj = drop.value %}').render!(context)
115
- context.resource_limits.assign_score
116
- end
117
- end
@@ -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