Class: Liquid::Strainer

Inherits:
Object
  • Object
show all
Defined in:
lib/liquid/strainer.rb

Overview

Strainer is the parent class for the filters system. New filters are mixed into the strainer class which is then instanciated for each liquid template render run.

One of the strainer’s responsibilities is to keep malicious method calls out

Constant Summary collapse

@@required_methods =
["__send__", "__id__", "respond_to?", "extend", "methods"]
@@filters =
[]

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(context) ⇒ Strainer

Returns a new instance of Strainer.



12
13
14
# File 'lib/liquid/strainer.rb', line 12

def initialize(context)
  @context = context
end

Class Method Details

.create(context) ⇒ Object



21
22
23
24
25
# File 'lib/liquid/strainer.rb', line 21

def self.create(context)
  strainer = Strainer.new(context)
  @@filters.each { |m| strainer.extend(m) }
  strainer
end

.global_filter(filter) ⇒ Object

Raises:

  • (StandardError)


16
17
18
19
# File 'lib/liquid/strainer.rb', line 16

def self.global_filter(filter)
  raise StandardError, "Passed filter is not a module" unless filter.is_a?(Module)      
  @@filters << filter
end

Instance Method Details

#respond_to?(method) ⇒ Boolean

Returns:

  • (Boolean)


27
28
29
30
31
32
# File 'lib/liquid/strainer.rb', line 27

def respond_to?(method)
  method_name = method.to_s
  return false if method_name =~ /^__/ 
  return false if @@required_methods.include?(method_name)
  super
end