mirror of
https://github.com/Shopify/liquid.git
synced 2026-09-12 23:40:45 -07:00
Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3af10eb58c |
@@ -24,11 +24,11 @@ module Liquid
|
||||
|
||||
include(filter)
|
||||
|
||||
filter_methods.merge(filter.public_instance_methods.map(&:to_s))
|
||||
filter_methods.merge(filter.public_instance_methods)
|
||||
end
|
||||
|
||||
def invokable?(method)
|
||||
filter_methods.include?(method.to_s)
|
||||
filter_methods.include?(method.to_sym)
|
||||
end
|
||||
|
||||
def inherited(subclass)
|
||||
@@ -36,6 +36,9 @@ module Liquid
|
||||
subclass.instance_variable_set(:@filter_methods, @filter_methods.dup)
|
||||
end
|
||||
|
||||
# Assuming the filter name is a string is deprecated, explicitly
|
||||
# cast to_s or to_sym for compatibility with liquid 6, where it is
|
||||
# planned to return as a symbol.
|
||||
def filter_method_names
|
||||
filter_methods.map(&:to_s).to_a
|
||||
end
|
||||
@@ -48,6 +51,7 @@ module Liquid
|
||||
end
|
||||
|
||||
def invoke(method, *args)
|
||||
method = method.to_sym
|
||||
if self.class.invokable?(method)
|
||||
send(method, *args)
|
||||
elsif @context.strict_filters
|
||||
|
||||
+11
-3
@@ -18,7 +18,7 @@ module Liquid
|
||||
JustTagAttributes = /\A#{TagAttributes}\z/o
|
||||
MarkupWithQuotedFragment = /(#{QuotedFragment})(.*)/om
|
||||
|
||||
attr_accessor :filters, :name, :line_number
|
||||
attr_accessor :name, :line_number
|
||||
attr_reader :parse_context
|
||||
alias_method :options, :parse_context
|
||||
|
||||
@@ -52,7 +52,7 @@ module Liquid
|
||||
filters = Regexp.last_match(1).scan(FilterParser)
|
||||
filters.each do |f|
|
||||
next unless f =~ /\w+/
|
||||
filtername = Regexp.last_match(0)
|
||||
filtername = Regexp.last_match(0).to_sym
|
||||
filterargs = f.scan(FilterArgsRegex).flatten
|
||||
@filters << parse_filter_expressions(filtername, filterargs)
|
||||
end
|
||||
@@ -67,13 +67,21 @@ module Liquid
|
||||
|
||||
@name = parse_context.parse_expression(p.expression)
|
||||
while p.consume?(:pipe)
|
||||
filtername = p.consume(:id)
|
||||
filtername = p.consume(:id).to_sym
|
||||
filterargs = p.consume?(:colon) ? parse_filterargs(p) : []
|
||||
@filters << parse_filter_expressions(filtername, filterargs)
|
||||
end
|
||||
p.consume(:end_of_string)
|
||||
end
|
||||
|
||||
# Assuming the filter name is a string is deprecated, explicitly
|
||||
# cast to_s or to_sym for compatibility with liquid 6, where it is
|
||||
# planned to return as a symbol.
|
||||
def filters
|
||||
# Remove to_s in liquid 6.0
|
||||
@filters.map { |key, *args| [key.to_s, *args].freeze }.freeze
|
||||
end
|
||||
|
||||
def parse_filterargs(p)
|
||||
# first argument
|
||||
filterargs = [p.argument]
|
||||
|
||||
@@ -60,7 +60,7 @@ class StrainerTemplateUnitTest < Minitest::Test
|
||||
with_global_filter do
|
||||
strainer = Context.new.strainer
|
||||
strainer.class.add_filter(PublicMethodOverrideFilter)
|
||||
assert(strainer.class.send(:filter_methods).include?('public_filter'))
|
||||
assert(strainer.class.filter_method_names.include?('public_filter'))
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user