From 5350f4323af0de675edea51c04572b8096fc3b0e Mon Sep 17 00:00:00 2001 From: Holger Just Date: Mon, 2 Jul 2012 20:54:10 +0200 Subject: [PATCH] Fix the Strainer patch to enforce a filter array Up until now, the patch used to be a no-op. While the filters class attribute was set correctly, the methods using it were not actually overridden as they are only included above the existing methods in the module chain. This resulted in an arbitrary load order of filters on Ruby 1.8. As such, our overridden standard filters might not have actually overridden anything. Still, the patch can be completely removed once we either require Ruby 1.9 (as we have ordered ahshes by default then) or once https://github.com/Shopify/liquid/pull/87 was merged and released upstream. --- lib/chili_project/liquid/liquid_ext/strainer.rb | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/lib/chili_project/liquid/liquid_ext/strainer.rb b/lib/chili_project/liquid/liquid_ext/strainer.rb index f2b65c50..7a7e3c61 100644 --- a/lib/chili_project/liquid/liquid_ext/strainer.rb +++ b/lib/chili_project/liquid/liquid_ext/strainer.rb @@ -21,18 +21,23 @@ module ChiliProject base.extend(ClassMethods) base.class_attribute :filters, :instance_reader => false, :instance_writer => false - base.class_eval <<-RUBY, __FILE__, __LINE__ + 1 - self.filters = @@filters.values - RUBY + base.class_eval do + self.filters = base.send(:class_variable_get, '@@filters').values + + class << self + alias_method_chain :global_filter, :filter_array + alias_method_chain :create, :filter_array + end + end end module ClassMethods - def global_filter(filter) + def global_filter_with_filter_array(filter) raise ArgumentError, "Passed filter is not a module" unless filter.is_a?(Module) - filters += [filter] + self.filters += [filter] end - def create(context) + def create_with_filter_array(context) strainer = self.new(context) filters.each { |filter| strainer.extend(filter) } strainer