mirror of
https://github.com/Shopify/liquid.git
synced 2026-10-03 00:55:11 -07:00
Rename before_method as liquid_method_missing
This commit is contained in:
@@ -15,6 +15,7 @@
|
|||||||
* Ruby 1.9 support dropped (#491) [Justin Li]
|
* Ruby 1.9 support dropped (#491) [Justin Li]
|
||||||
* Liquid::Template.file_system's read_template_file method is no longer passed the context. (#441) [James Reid-Smith]
|
* Liquid::Template.file_system's read_template_file method is no longer passed the context. (#441) [James Reid-Smith]
|
||||||
* Remove support for `liquid_methods`
|
* Remove support for `liquid_methods`
|
||||||
|
* Rename Drop method `before_method` as `liquid_method_missing` (#661) [Thierry Joyal]
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
* Fix sort filter behaviour with empty array input (#652) [Marcel Cary]
|
* Fix sort filter behaviour with empty array input (#652) [Marcel Cary]
|
||||||
|
|||||||
+4
-4
@@ -18,15 +18,15 @@ module Liquid
|
|||||||
# tmpl = Liquid::Template.parse( ' {% for product in product.top_sales %} {{ product.name }} {%endfor%} ' )
|
# tmpl = Liquid::Template.parse( ' {% for product in product.top_sales %} {{ product.name }} {%endfor%} ' )
|
||||||
# tmpl.render('product' => ProductDrop.new ) # will invoke top_sales query.
|
# tmpl.render('product' => ProductDrop.new ) # will invoke top_sales query.
|
||||||
#
|
#
|
||||||
# Your drop can either implement the methods sans any parameters or implement the before_method(name) method which is a
|
# Your drop can either implement the methods sans any parameters
|
||||||
# catch all.
|
# or implement the liquid_method_missing(name) method which is a catch all.
|
||||||
class Drop
|
class Drop
|
||||||
attr_writer :context
|
attr_writer :context
|
||||||
|
|
||||||
EMPTY_STRING = ''.freeze
|
EMPTY_STRING = ''.freeze
|
||||||
|
|
||||||
# Catch all for the method
|
# Catch all for the method
|
||||||
def before_method(_method)
|
def liquid_method_missing(_method)
|
||||||
nil
|
nil
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -35,7 +35,7 @@ module Liquid
|
|||||||
if method_or_key && method_or_key != EMPTY_STRING && self.class.invokable?(method_or_key)
|
if method_or_key && method_or_key != EMPTY_STRING && self.class.invokable?(method_or_key)
|
||||||
send(method_or_key)
|
send(method_or_key)
|
||||||
else
|
else
|
||||||
before_method(method_or_key)
|
liquid_method_missing(method_or_key)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ class ContextDrop < Liquid::Drop
|
|||||||
@context['forloop.index']
|
@context['forloop.index']
|
||||||
end
|
end
|
||||||
|
|
||||||
def before_method(method)
|
def liquid_method_missing(method)
|
||||||
@context[method]
|
@context[method]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -30,8 +30,8 @@ class ProductDrop < Liquid::Drop
|
|||||||
end
|
end
|
||||||
|
|
||||||
class CatchallDrop < Liquid::Drop
|
class CatchallDrop < Liquid::Drop
|
||||||
def before_method(method)
|
def liquid_method_missing(method)
|
||||||
'method: ' << method.to_s
|
'catchall_method: ' << method.to_s
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -59,7 +59,7 @@ class ProductDrop < Liquid::Drop
|
|||||||
end
|
end
|
||||||
|
|
||||||
class EnumerableDrop < Liquid::Drop
|
class EnumerableDrop < Liquid::Drop
|
||||||
def before_method(method)
|
def liquid_method_missing(method)
|
||||||
method
|
method
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -93,7 +93,7 @@ end
|
|||||||
class RealEnumerableDrop < Liquid::Drop
|
class RealEnumerableDrop < Liquid::Drop
|
||||||
include Enumerable
|
include Enumerable
|
||||||
|
|
||||||
def before_method(method)
|
def liquid_method_missing(method)
|
||||||
method
|
method
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -157,14 +157,14 @@ class DropsTest < Minitest::Test
|
|||||||
assert_equal ' text1 ', output
|
assert_equal ' text1 ', output
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_unknown_method
|
def test_catchall_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 ' catchall_method: unknown ', output
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_integer_argument_drop
|
def test_catchall_integer_argument_drop
|
||||||
output = Liquid::Template.parse(' {{ product.catchall[8] }} ').render!('product' => ProductDrop.new)
|
output = Liquid::Template.parse(' {{ product.catchall[8] }} ').render!('product' => ProductDrop.new)
|
||||||
assert_equal ' method: 8 ', output
|
assert_equal ' catchall_method: 8 ', output
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_text_array_drop
|
def test_text_array_drop
|
||||||
@@ -231,7 +231,7 @@ class DropsTest < Minitest::Test
|
|||||||
assert_equal '3', Liquid::Template.parse('{{collection.size}}').render!('collection' => EnumerableDrop.new)
|
assert_equal '3', Liquid::Template.parse('{{collection.size}}').render!('collection' => EnumerableDrop.new)
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_enumerable_drop_will_invoke_before_method_for_clashing_method_names
|
def test_enumerable_drop_will_invoke_liquid_method_missing_for_clashing_method_names
|
||||||
["select", "each", "map", "cycle"].each do |method|
|
["select", "each", "map", "cycle"].each do |method|
|
||||||
assert_equal method.to_s, Liquid::Template.parse("{{collection.#{method}}}").render!('collection' => EnumerableDrop.new)
|
assert_equal method.to_s, Liquid::Template.parse("{{collection.#{method}}}").render!('collection' => EnumerableDrop.new)
|
||||||
assert_equal method.to_s, Liquid::Template.parse("{{collection[\"#{method}\"]}}").render!('collection' => EnumerableDrop.new)
|
assert_equal method.to_s, Liquid::Template.parse("{{collection[\"#{method}\"]}}").render!('collection' => EnumerableDrop.new)
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ require 'test_helper'
|
|||||||
require 'timeout'
|
require 'timeout'
|
||||||
|
|
||||||
class TemplateContextDrop < Liquid::Drop
|
class TemplateContextDrop < Liquid::Drop
|
||||||
def before_method(method)
|
def liquid_method_missing(method)
|
||||||
method
|
method
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user