Class: Nitro::Morphing

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

Overview

A compiler module that translates xml stream. Multiple ‘key’ attributes are supported per element.

Defined Under Namespace

Classes: Listener

Class Method Summary collapse

Class Method Details

.add_morpher(key, klass) ⇒ Object Also known as: add



251
252
253
# File 'lib/nitro/compiler/morphing.rb', line 251

def add_morpher(key, klass)
  @morphers[key.to_s] = klass
end

.delete_morpher(key) ⇒ Object Also known as: delete



256
257
258
# File 'lib/nitro/compiler/morphing.rb', line 256

def delete_morpher(key)
  @morphers.delete(key)
end

.emit_end(name) ⇒ Object



226
227
228
# File 'lib/nitro/compiler/morphing.rb', line 226

def self.emit_end(name)
  "</#{name}>"
end

.emit_start(name, attributes) ⇒ Object



221
222
223
224
# File 'lib/nitro/compiler/morphing.rb', line 221

def self.emit_start(name, attributes)
  attrs = attributes.map{ |k, v| %|#{k}="#{v}"| }.join(' ')
  attrs.blank? ? "<#{name}>" : "<#{name} #{attrs}>"
end

.morphersObject



243
244
245
# File 'lib/nitro/compiler/morphing.rb', line 243

def morphers
  @morphers
end

.morphers=(hash) ⇒ Object



247
248
249
# File 'lib/nitro/compiler/morphing.rb', line 247

def morphers=(hash)
  @morphers = hash
end

.transform(source, compiler = nil) ⇒ Object



230
231
232
233
234
235
# File 'lib/nitro/compiler/morphing.rb', line 230

def self.transform(source, compiler = nil)
  listener = Listener.new
  listener.compiler = compiler
  REXML::Document.parse_stream(source, listener)
  return listener.buffer
end