Class: Twig::TwigFilter

Inherits:
Callable show all
Defined in:
lib/twig/twig_filter.rb

Instance Attribute Summary

Attributes inherited from Callable

#arguments, #callable, #dynamic_name, #name

Instance Method Summary collapse

Methods inherited from Callable

#needs_charset?, #needs_context?, #needs_environment?, #with_dynamic_arguments

Constructor Details

#initialize(name, callable = nil, options = {}) ⇒ TwigFilter

Returns a new instance of TwigFilter.



5
6
7
8
9
10
11
12
13
14
15
# File 'lib/twig/twig_filter.rb', line 5

def initialize(name, callable = nil, options = {})
  super

  @options = {
    is_safe: nil,
    is_safe_callback: nil,
    pre_escape: nil,
    preserves_safety: nil,
    node_class: Node::Expression::Filter,
  }.merge(@options)
end

Instance Method Details

#node_classObject



37
38
39
# File 'lib/twig/twig_filter.rb', line 37

def node_class
  @options[:node_class]
end

#pre_escapeObject



29
30
31
# File 'lib/twig/twig_filter.rb', line 29

def pre_escape
  @options[:pre_escape]
end

#preserves_safetyObject



25
26
27
# File 'lib/twig/twig_filter.rb', line 25

def preserves_safety
  @options[:preserves_safety] || []
end

#safe(filter_args) ⇒ Object

Parameters:



18
19
20
21
22
23
# File 'lib/twig/twig_filter.rb', line 18

def safe(filter_args)
  return @options[:is_safe] unless @options[:is_safe].nil?
  return @options[:is_safe_callback].call(filter_args) unless @options[:is_safe_callback].nil?

  []
end

#typeObject



33
34
35
# File 'lib/twig/twig_filter.rb', line 33

def type
  :filter
end