From 37a0fe213b23e0fceb850a791cf400ca9f85e52a Mon Sep 17 00:00:00 2001 From: "Mark H. Wilkinson" Date: Tue, 12 Apr 2011 13:47:27 +0100 Subject: [PATCH 1/3] Fix text method name clash. --- test/lib/liquid/drop_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/lib/liquid/drop_test.rb b/test/lib/liquid/drop_test.rb index 303d14a1..9755280a 100644 --- a/test/lib/liquid/drop_test.rb +++ b/test/lib/liquid/drop_test.rb @@ -88,7 +88,7 @@ class DropsTest < Test::Unit::TestCase end - def test_text_drop + def test_unknown_method output = Liquid::Template.parse( ' {{ product.catchall.unknown }} ' ).render('product' => ProductDrop.new) assert_equal ' method: unknown ', output From 662b2983fefb07012d51632a64243433ce81b3e9 Mon Sep 17 00:00:00 2001 From: "Mark H. Wilkinson" Date: Tue, 12 Apr 2011 13:50:50 +0100 Subject: [PATCH 2/3] Failing test for integer drop lookup. --- test/lib/liquid/drop_test.rb | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/test/lib/liquid/drop_test.rb b/test/lib/liquid/drop_test.rb index 9755280a..4d74a1d9 100644 --- a/test/lib/liquid/drop_test.rb +++ b/test/lib/liquid/drop_test.rb @@ -36,7 +36,7 @@ class ProductDrop < Liquid::Drop class CatchallDrop < Liquid::Drop def before_method(method) - return 'method: ' << method + return 'method: ' << method.to_s end end @@ -94,6 +94,11 @@ class DropsTest < Test::Unit::TestCase 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 output = Liquid::Template.parse( '{% for text in product.texts.array %} {{text}} {% endfor %}' ).render('product' => ProductDrop.new) assert_equal ' text1 text2 ', output From 935d3530af0e459e369ee4b183d5b17df1a4b388 Mon Sep 17 00:00:00 2001 From: "Mark H. Wilkinson" Date: Tue, 12 Apr 2011 14:11:06 +0100 Subject: [PATCH 3/3] Handle invoking drops for keys that are not strings. For example, {{ pages[8] ... }} will result in the integer value 8 being passed to invoke_drop. --- lib/liquid/drop.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/liquid/drop.rb b/lib/liquid/drop.rb index 1901871d..db507eb0 100644 --- a/lib/liquid/drop.rb +++ b/lib/liquid/drop.rb @@ -28,11 +28,11 @@ module Liquid end # called by liquid to invoke a drop - def invoke_drop(method) - if self.class.public_method_defined?(method) - send(method) + def invoke_drop(method_or_key) + if self.class.public_method_defined?(method_or_key.to_s.to_sym) + send(method_or_key.to_s.to_sym) else - before_method(method) + before_method(method_or_key) end end