mirror of
https://github.com/Shopify/liquid.git
synced 2026-09-20 03:10:39 -07:00
Fix mapping over proc attributes
This commit is contained in:
@@ -173,7 +173,8 @@ module Liquid
|
|||||||
if property == "to_liquid".freeze
|
if property == "to_liquid".freeze
|
||||||
e
|
e
|
||||||
elsif e.respond_to?(:[])
|
elsif e.respond_to?(:[])
|
||||||
e[property]
|
r = e[property]
|
||||||
|
r.is_a?(Proc) ? r.call : r
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -249,6 +249,19 @@ class StandardFiltersTest < Minitest::Test
|
|||||||
assert_template_result "testfoo", templ, "procs" => [p]
|
assert_template_result "testfoo", templ, "procs" => [p]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_map_over_drops_returning_procs
|
||||||
|
drops = [
|
||||||
|
{
|
||||||
|
"proc" => ->{ "foo" },
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"proc" => ->{ "bar" },
|
||||||
|
},
|
||||||
|
]
|
||||||
|
templ = '{{ drops | map: "proc" }}'
|
||||||
|
assert_template_result "foobar", templ, "drops" => drops
|
||||||
|
end
|
||||||
|
|
||||||
def test_map_works_on_enumerables
|
def test_map_works_on_enumerables
|
||||||
assert_template_result "123", '{{ foo | map: "foo" }}', "foo" => TestEnumerable.new
|
assert_template_result "123", '{{ foo | map: "foo" }}', "foo" => TestEnumerable.new
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user