mirror of
https://github.com/Shopify/liquid.git
synced 2026-09-12 23:40:45 -07:00
Make before_method work more like method_missing
This commit is contained in:
+6
-4
@@ -28,10 +28,12 @@ module Liquid
|
|||||||
end
|
end
|
||||||
|
|
||||||
# called by liquid to invoke a drop
|
# called by liquid to invoke a drop
|
||||||
def invoke_drop(method)
|
def invoke_drop(method)
|
||||||
result = before_method(method)
|
if self.class.public_instance_methods.include?(method.to_s)
|
||||||
result ||= send(method.to_sym) if self.class.public_instance_methods.include?(method.to_s)
|
send(method.to_sym)
|
||||||
result
|
else
|
||||||
|
before_method(method)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def has_key?(name)
|
def has_key?(name)
|
||||||
|
|||||||
+9
-2
@@ -62,13 +62,16 @@ class ProductDrop < Liquid::Drop
|
|||||||
end
|
end
|
||||||
|
|
||||||
class EnumerableDrop < Liquid::Drop
|
class EnumerableDrop < Liquid::Drop
|
||||||
include Enumerable
|
|
||||||
|
def size
|
||||||
|
3
|
||||||
|
end
|
||||||
|
|
||||||
def each
|
def each
|
||||||
yield 1
|
yield 1
|
||||||
yield 2
|
yield 2
|
||||||
yield 3
|
yield 3
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
@@ -147,6 +150,10 @@ class DropsTest < Test::Unit::TestCase
|
|||||||
def test_enumerable_drop
|
def test_enumerable_drop
|
||||||
assert_equal '123', Liquid::Template.parse( '{% for c in collection %}{{c}}{% endfor %}').render('collection' => EnumerableDrop.new)
|
assert_equal '123', Liquid::Template.parse( '{% for c in collection %}{{c}}{% endfor %}').render('collection' => EnumerableDrop.new)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_enumerable_drop_size
|
||||||
|
assert_equal '3', Liquid::Template.parse( '{{collection.size}}').render('collection' => EnumerableDrop.new)
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user