mirror of
https://github.com/Shopify/liquid.git
synced 2026-09-15 00:40:40 -07:00
Compare commits
3
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d209d1467e | ||
|
|
a617b91ddd | ||
|
|
11c2dba8fa |
+1
-1
@@ -1 +1 @@
|
|||||||
3.3.6
|
3.4.1
|
||||||
|
|||||||
@@ -1063,7 +1063,18 @@ module Liquid
|
|||||||
end
|
end
|
||||||
|
|
||||||
def join(glue)
|
def join(glue)
|
||||||
to_a.join(glue.to_s)
|
first = true
|
||||||
|
output = +""
|
||||||
|
@input.each do |item|
|
||||||
|
if first
|
||||||
|
first = false
|
||||||
|
else
|
||||||
|
output << glue
|
||||||
|
end
|
||||||
|
|
||||||
|
output << Liquid::Utils.to_s(item)
|
||||||
|
end
|
||||||
|
output
|
||||||
end
|
end
|
||||||
|
|
||||||
def concat(args)
|
def concat(args)
|
||||||
|
|||||||
+28
-18
@@ -90,34 +90,38 @@ module Liquid
|
|||||||
obj
|
obj
|
||||||
end
|
end
|
||||||
|
|
||||||
if RUBY_VERSION >= '3.4'
|
def self.to_s(obj, seen = {})
|
||||||
def self.to_s(obj, seen = {})
|
case obj
|
||||||
case obj
|
when Hash
|
||||||
when Hash
|
# If the custom hash implementation overrides `#to_s`, use their
|
||||||
|
# custom implementation. Otherwise we use Liquid's default
|
||||||
|
# implementation.
|
||||||
|
if obj.class.instance_method(:to_s) == HASH_TO_S_METHOD
|
||||||
hash_inspect(obj, seen)
|
hash_inspect(obj, seen)
|
||||||
when Array
|
|
||||||
array_inspect(obj, seen)
|
|
||||||
else
|
else
|
||||||
obj.to_s
|
obj.to_s
|
||||||
end
|
end
|
||||||
|
when Array
|
||||||
|
array_inspect(obj, seen)
|
||||||
|
else
|
||||||
|
obj.to_s
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def self.inspect(obj, seen = {})
|
def self.inspect(obj, seen = {})
|
||||||
case obj
|
case obj
|
||||||
when Hash
|
when Hash
|
||||||
|
# If the custom hash implementation overrides `#inspect`, use their
|
||||||
|
# custom implementation. Otherwise we use Liquid's default
|
||||||
|
# implementation.
|
||||||
|
if obj.class.instance_method(:inspect) == HASH_INSPECT_METHOD
|
||||||
hash_inspect(obj, seen)
|
hash_inspect(obj, seen)
|
||||||
when Array
|
|
||||||
array_inspect(obj, seen)
|
|
||||||
else
|
else
|
||||||
obj.inspect
|
obj.inspect
|
||||||
end
|
end
|
||||||
end
|
when Array
|
||||||
else
|
array_inspect(obj, seen)
|
||||||
def self.to_s(obj, seen = nil)
|
else
|
||||||
obj.to_s
|
|
||||||
end
|
|
||||||
|
|
||||||
def self.inspect(obj, seen = nil)
|
|
||||||
obj.inspect
|
obj.inspect
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -175,5 +179,11 @@ module Liquid
|
|||||||
ensure
|
ensure
|
||||||
seen.delete(hash.object_id)
|
seen.delete(hash.object_id)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
HASH_TO_S_METHOD = Hash.instance_method(:to_s)
|
||||||
|
private_constant :HASH_TO_S_METHOD
|
||||||
|
|
||||||
|
HASH_INSPECT_METHOD = Hash.instance_method(:inspect)
|
||||||
|
private_constant :HASH_INSPECT_METHOD
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -80,4 +80,27 @@ class HashRenderingTest < Minitest::Test
|
|||||||
def test_render_hash_with_hash_key
|
def test_render_hash_with_hash_key
|
||||||
assert_template_result("{{\"foo\"=>\"bar\"}=>42}", "{{ my_hash }}", { "my_hash" => { Hash["foo" => "bar"] => 42 } })
|
assert_template_result("{{\"foo\"=>\"bar\"}=>42}", "{{ my_hash }}", { "my_hash" => { Hash["foo" => "bar"] => 42 } })
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_join_filter_with_hash
|
||||||
|
array = [{ "key1" => "value1" }, { "key2" => "value2" }]
|
||||||
|
glue = { "lol" => "wut" }
|
||||||
|
assert_template_result("{\"key1\"=>\"value1\"}{\"lol\"=>\"wut\"}{\"key2\"=>\"value2\"}", "{{ my_array | join: glue }}", { "my_array" => array, "glue" => glue })
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_rendering_hash_with_custom_to_s_method_uses_custom_to_s
|
||||||
|
my_hash = Class.new(Hash) do
|
||||||
|
def to_s
|
||||||
|
"kewl"
|
||||||
|
end
|
||||||
|
end.new
|
||||||
|
|
||||||
|
assert_template_result("kewl", "{{ my_hash }}", { "my_hash" => my_hash })
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_rendering_hash_without_custom_to_s_uses_default_inspect
|
||||||
|
my_hash = Class.new(Hash).new
|
||||||
|
my_hash[:foo] = :bar
|
||||||
|
|
||||||
|
assert_template_result("{:foo=>:bar}", "{{ my_hash }}", { "my_hash" => my_hash })
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user