Class: Raw::MorphFilter

Inherits:
Object
  • Object
show all
Defined in:
lib/raw/compiler/filter/morph.rb

Overview

A Filter that transforms an xml stream. Multiple ‘key’ attributes are supported per element.

Defined Under Namespace

Classes: Listener

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(morphers = nil) ⇒ MorphFilter

Initialize the filter.



95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# File 'lib/raw/compiler/filter/morph.rb', line 95

def initialize(morphers = nil)
  unless @morphers = morphers
    require "raw/compiler/filter/morph/times"
    require "raw/compiler/filter/morph/each"
    require "raw/compiler/filter/morph/for"
    require "raw/compiler/filter/morph/if"
    require "raw/compiler/filter/morph/selected_if"
    
    @morphers = [ 
      TimesMorpher, 
      EachMorpher, 
      ForMorpher, 
      IfMorpher, 
      SelectedIfMorpher 
    ]
  end
end

Instance Attribute Details

#morphersObject

A collection of morphers registered with this filter.



91
92
93
# File 'lib/raw/compiler/filter/morph.rb', line 91

def morphers
  @morphers
end

Instance Method Details

#apply(source) ⇒ Object

Apply the filter.



115
116
117
118
119
# File 'lib/raw/compiler/filter/morph.rb', line 115

def apply(source)
  listen = Listener.new(self)
  REXML::Document.parse_stream(source, listen)
  return listen.buffer
end