2012-01-16 23:45:47 +04:00
|
|
|
#-- encoding: UTF-8
|
|
|
|
#-- copyright
|
|
|
|
# ChiliProject is a project management system.
|
|
|
|
#
|
2012-01-18 22:25:13 +04:00
|
|
|
# Copyright (C) 2010-2012 the ChiliProject Team
|
2012-01-16 23:45:47 +04:00
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or
|
|
|
|
# modify it under the terms of the GNU General Public License
|
|
|
|
# as published by the Free Software Foundation; either version 2
|
|
|
|
# of the License, or (at your option) any later version.
|
|
|
|
#
|
|
|
|
# See doc/COPYRIGHT.rdoc for more details.
|
|
|
|
#++
|
|
|
|
|
|
|
|
# Required until https://github.com/Shopify/liquid/pull/87 got merged upstream
|
|
|
|
module ChiliProject
|
|
|
|
module Liquid
|
|
|
|
module LiquidExt
|
|
|
|
module Strainer
|
|
|
|
def self.included(base)
|
|
|
|
base.extend(ClassMethods)
|
2012-01-18 13:19:04 +04:00
|
|
|
|
|
|
|
base.class_attribute :filters, :instance_reader => false, :instance_writer => false
|
2012-07-02 22:54:10 +04:00
|
|
|
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
|
2012-01-16 23:45:47 +04:00
|
|
|
end
|
|
|
|
|
|
|
|
module ClassMethods
|
2012-07-02 22:54:10 +04:00
|
|
|
def global_filter_with_filter_array(filter)
|
2012-01-16 23:45:47 +04:00
|
|
|
raise ArgumentError, "Passed filter is not a module" unless filter.is_a?(Module)
|
2012-07-02 22:54:10 +04:00
|
|
|
self.filters += [filter]
|
2012-01-16 23:45:47 +04:00
|
|
|
end
|
|
|
|
|
2012-07-02 22:54:10 +04:00
|
|
|
def create_with_filter_array(context)
|
2012-01-16 23:45:47 +04:00
|
|
|
strainer = self.new(context)
|
2012-01-18 13:19:04 +04:00
|
|
|
filters.each { |filter| strainer.extend(filter) }
|
2012-01-16 23:45:47 +04:00
|
|
|
strainer
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|