Class: Nitro::Morphing::Listener

Inherits:
Object
  • Object
show all
Includes:
REXML::StreamListener
Defined in:
lib/nitro/compiler/morphing.rb

Overview

– The listener used to parse the xml stream.

TODO: add support for morphing comments, text, etc. ++

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeListener

Returns a new instance of Listener.



162
163
164
165
166
# File 'lib/nitro/compiler/morphing.rb', line 162

def initialize
  super
  @buffer = ''
  @stack = []
end

Instance Attribute Details

#bufferObject

Returns the value of attribute buffer.



160
161
162
# File 'lib/nitro/compiler/morphing.rb', line 160

def buffer
  @buffer
end

#compilerObject

The compiler that calls this compiling stage. Useful for advanced morphing effects and inter-stage communication.



158
159
160
# File 'lib/nitro/compiler/morphing.rb', line 158

def compiler
  @compiler
end

Instance Method Details

#cdata(content) ⇒ Object



205
206
207
# File 'lib/nitro/compiler/morphing.rb', line 205

def cdata(content)
  @buffer << "<![CDATA[#{content}]]>"
end

#comment(c) ⇒ Object



209
210
211
212
213
# File 'lib/nitro/compiler/morphing.rb', line 209

def comment(c)
  unless Nitro::Template.strip_xml_comments
    @buffer << "<!--#{c}-->"
  end
end

#doctype(name, pub_sys, long_name, uri) ⇒ Object



215
216
217
# File 'lib/nitro/compiler/morphing.rb', line 215

def doctype(name, pub_sys, long_name, uri)   
  @buffer << "<!DOCTYPE #{name} #{pub_sys} #{long_name} #{uri}>\n"
end

#instruction(name, attributes) ⇒ Object



201
202
203
# File 'lib/nitro/compiler/morphing.rb', line 201

def instruction(name, attributes)
  @buffer << "<?#{name}#{attributes}?>"
end

#tag_end(name) ⇒ Object



190
191
192
193
194
195
# File 'lib/nitro/compiler/morphing.rb', line 190

def tag_end(name)    
  morphers = @stack.pop
  morphers.reverse.each { |h| h.before_end(@buffer) }
  @buffer << Morphing.emit_end(name)
  morphers.reverse.each { |h| h.after_end(@buffer) }
end

#tag_start(name, attributes) ⇒ Object



168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
# File 'lib/nitro/compiler/morphing.rb', line 168

def tag_start(name, attributes)    
  morphers = []
  
  #for key, val in attributes
  #  if morpher_class = Morphing.morphers[key]
  #    morphers << morpher_class.new(key, name, attributes)
  #  end
  #end
  
  Morphing.morphers.each do |key, morpher_class|
    if attributes.has_key? key
      morphers << morpher_class.new(key, name, attributes, compiler)
    end
  end
  
  morphers.each { |h| h.before_start(@buffer) }
  @buffer << Morphing.emit_start(name, attributes)
  morphers.each { |h| h.after_start(@buffer) }

  @stack.push(morphers)      
end

#text(str) ⇒ Object



197
198
199
# File 'lib/nitro/compiler/morphing.rb', line 197

def text(str)
  @buffer << str
end