Class: Opulent::Filters::Filter

Inherits:
Object
  • Object
show all
Defined in:
lib/opulent/filters.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, options) ⇒ Filter

Set tag and attribute options for filter



33
34
35
36
37
# File 'lib/opulent/filters.rb', line 33

def initialize(name, options)
  @name = name
  @options = options
  @loaded = false
end

Instance Attribute Details

#loadedObject

Returns the value of attribute loaded.



29
30
31
# File 'lib/opulent/filters.rb', line 29

def loaded
  @loaded
end

#nameObject

Returns the value of attribute name.



29
30
31
# File 'lib/opulent/filters.rb', line 29

def name
  @name
end

#optionsObject

Returns the value of attribute options.



29
30
31
# File 'lib/opulent/filters.rb', line 29

def options
  @options
end

Instance Method Details

#gem_nameObject

RubyGems name for explicit library require



70
71
72
73
# File 'lib/opulent/filters.rb', line 70

def gem_name
  fail NoMethodError
  # "gem_name"
end

#install_errorObject

Error message to be shown in order to provide installation instructions for the developer



57
58
59
# File 'lib/opulent/filters.rb', line 57

def install_error
  "gem install #{gem_name}"
end

#load_filterObject

Error output in case the filter does not exist



41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/opulent/filters.rb', line 41

def load_filter
  return if gem_name.nil? || @loaded

  # Try to load the library associated to the chosen filter
  begin
    require gem_name
    @loaded = true
  rescue LoadError
    # Error output with filter name and installation instructions
    Logger.error :compile, :filter_load, @name, install_error
  end
end

#render(_code, _options = {}) ⇒ Object

Process input code using this filter and return the output to the evaluation method from the Filter Node



64
65
66
# File 'lib/opulent/filters.rb', line 64

def render(_code, _options = {})
  fail NoMethodError
end