mirror of
https://github.com/Shopify/liquid.git
synced 2026-09-12 23:40:45 -07:00
Use array instead of Hash to keep the registered filters
1.8.7 compatibility fix In Ruby 1.8.7, Hash does not preserve insertion ordering as Array does. This could cause a problem when registering filters which depend on others and the registration order is important. So, the @@filters variable was changed to array where the order of the filters is the same as the insertion order.
This commit is contained in:
@@ -8,7 +8,7 @@ module Liquid
|
||||
# The Strainer only allows method calls defined in filters given to it via Strainer.global_filter,
|
||||
# Context#add_filters or Template.register_filter
|
||||
class Strainer #:nodoc:
|
||||
@@filters = {}
|
||||
@@filters = []
|
||||
@@known_filters = Set.new
|
||||
@@known_methods = Set.new
|
||||
|
||||
@@ -19,7 +19,7 @@ module Liquid
|
||||
def self.global_filter(filter)
|
||||
raise ArgumentError, "Passed filter is not a module" unless filter.is_a?(Module)
|
||||
add_known_filter(filter)
|
||||
@@filters[filter.name] = filter
|
||||
@@filters << filter unless @@filters.include?(filter)
|
||||
end
|
||||
|
||||
def self.add_known_filter(filter)
|
||||
@@ -34,7 +34,7 @@ module Liquid
|
||||
|
||||
def self.create(context)
|
||||
strainer = Strainer.new(context)
|
||||
@@filters.each { |k,m| strainer.extend(m) }
|
||||
@@filters.each { |m| strainer.extend(m) }
|
||||
strainer
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user