mirror of
https://github.com/Shopify/liquid.git
synced 2026-09-12 23:40:45 -07:00
Changed implementation of For in such a way that it only depends on the existence of a each method. This allows drops to simply implement each for enumeration
This commit is contained in:
@@ -59,6 +59,16 @@ class ProductDrop < Liquid::Drop
|
||||
def callmenot
|
||||
"protected"
|
||||
end
|
||||
end
|
||||
|
||||
class EnumerableDrop < Liquid::Drop
|
||||
include Enumerable
|
||||
|
||||
def each
|
||||
yield 1
|
||||
yield 2
|
||||
yield 3
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -132,6 +142,10 @@ class DropsTest < Test::Unit::TestCase
|
||||
|
||||
def test_access_context_from_drop
|
||||
assert_equal '123', Liquid::Template.parse( '{%for a in dummy%}{{ context.loop_pos }}{% endfor %}' ).render('context' => ContextDrop.new, 'dummy' => [1,2,3])
|
||||
end
|
||||
|
||||
def test_enumerable_drop
|
||||
assert_equal '123', Liquid::Template.parse( '{% for c in collection %}{{c}}{% endfor %}').render('collection' => EnumerableDrop.new)
|
||||
end
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user