mirror of
https://github.com/Shopify/liquid.git
synced 2026-10-02 16:45:12 -07:00
Merged pull request #54 from mhw/fix-drop-numeric-parameter.
Fix passing numeric parameter to drops
This commit is contained in:
+4
-4
@@ -28,11 +28,11 @@ 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_or_key)
|
||||||
if self.class.public_method_defined?(method)
|
if self.class.public_method_defined?(method_or_key.to_s.to_sym)
|
||||||
send(method)
|
send(method_or_key.to_s.to_sym)
|
||||||
else
|
else
|
||||||
before_method(method)
|
before_method(method_or_key)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ class ProductDrop < Liquid::Drop
|
|||||||
|
|
||||||
class CatchallDrop < Liquid::Drop
|
class CatchallDrop < Liquid::Drop
|
||||||
def before_method(method)
|
def before_method(method)
|
||||||
return 'method: ' << method
|
return 'method: ' << method.to_s
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -88,12 +88,17 @@ class DropsTest < Test::Unit::TestCase
|
|||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_text_drop
|
def test_unknown_method
|
||||||
output = Liquid::Template.parse( ' {{ product.catchall.unknown }} ' ).render('product' => ProductDrop.new)
|
output = Liquid::Template.parse( ' {{ product.catchall.unknown }} ' ).render('product' => ProductDrop.new)
|
||||||
assert_equal ' method: unknown ', output
|
assert_equal ' method: unknown ', output
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_integer_argument_drop
|
||||||
|
output = Liquid::Template.parse( ' {{ product.catchall[8] }} ' ).render('product' => ProductDrop.new)
|
||||||
|
assert_equal ' method: 8 ', output
|
||||||
|
end
|
||||||
|
|
||||||
def test_text_array_drop
|
def test_text_array_drop
|
||||||
output = Liquid::Template.parse( '{% for text in product.texts.array %} {{text}} {% endfor %}' ).render('product' => ProductDrop.new)
|
output = Liquid::Template.parse( '{% for text in product.texts.array %} {{text}} {% endfor %}' ).render('product' => ProductDrop.new)
|
||||||
assert_equal ' text1 text2 ', output
|
assert_equal ' text1 text2 ', output
|
||||||
|
|||||||
Reference in New Issue
Block a user