mirror of
https://github.com/Shopify/liquid.git
synced 2026-09-12 23:40:45 -07:00
Write one value at a time for array variables (#1863)
* Write one value at a time for array variables * Handle recursive array
This commit is contained in:
+12
-6
@@ -95,15 +95,21 @@ module Liquid
|
|||||||
|
|
||||||
def render_to_output_buffer(context, output)
|
def render_to_output_buffer(context, output)
|
||||||
obj = render(context)
|
obj = render(context)
|
||||||
|
render_obj_to_output(obj, output)
|
||||||
|
output
|
||||||
|
end
|
||||||
|
|
||||||
if obj.is_a?(Array)
|
def render_obj_to_output(obj, output)
|
||||||
output << obj.join
|
case obj
|
||||||
elsif obj.nil?
|
when NilClass
|
||||||
else
|
# Do nothing
|
||||||
|
when Array
|
||||||
|
obj.each do |o|
|
||||||
|
render_obj_to_output(o, output)
|
||||||
|
end
|
||||||
|
when
|
||||||
output << obj.to_s
|
output << obj.to_s
|
||||||
end
|
end
|
||||||
|
|
||||||
output
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def disabled?(_context)
|
def disabled?(_context)
|
||||||
|
|||||||
@@ -130,6 +130,10 @@ class VariableTest < Minitest::Test
|
|||||||
assert_template_result('bar', '{{ foo }}', { 'foo' => :bar })
|
assert_template_result('bar', '{{ foo }}', { 'foo' => :bar })
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_nested_array
|
||||||
|
assert_template_result('', '{{ foo }}', { 'foo' => [[nil]] })
|
||||||
|
end
|
||||||
|
|
||||||
def test_dynamic_find_var
|
def test_dynamic_find_var
|
||||||
assert_template_result('bar', '{{ [key] }}', { 'key' => 'foo', 'foo' => 'bar' })
|
assert_template_result('bar', '{{ [key] }}', { 'key' => 'foo', 'foo' => 'bar' })
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user