Class: Raw::MorphFilter::Listener
- Inherits:
-
Object
- Object
- Raw::MorphFilter::Listener
- Includes:
- REXML::StreamListener
- Defined in:
- lib/raw/compiler/filter/morph.rb
Overview
– The listener used to parse the xml stream. TODO: add support for morphing comments, text, etc. ++
Instance Attribute Summary collapse
-
#buffer ⇒ Object
Returns the value of attribute buffer.
Instance Method Summary collapse
- #cdata(content) ⇒ Object
- #comment(c) ⇒ Object
- #doctype(name, pub_sys, long_name, uri) ⇒ Object
- #emit_end(name) ⇒ Object
- #emit_start(name, attributes) ⇒ Object
-
#initialize(filter) ⇒ Listener
constructor
A new instance of Listener.
- #instruction(name, attributes) ⇒ Object
- #tag_end(name) ⇒ Object
- #tag_start(name, attributes) ⇒ Object
- #text(str) ⇒ Object
Constructor Details
#initialize(filter) ⇒ Listener
Returns a new instance of Listener.
27 28 29 30 31 32 |
# File 'lib/raw/compiler/filter/morph.rb', line 27 def initialize(filter) super() @filter = filter @buffer = "" @stack = [] end |
Instance Attribute Details
#buffer ⇒ Object
Returns the value of attribute buffer.
25 26 27 |
# File 'lib/raw/compiler/filter/morph.rb', line 25 def buffer @buffer end |
Instance Method Details
#cdata(content) ⇒ Object
65 66 67 |
# File 'lib/raw/compiler/filter/morph.rb', line 65 def cdata(content) @buffer << "<![CDATA[#{content}]]>" end |
#comment(c) ⇒ Object
69 70 71 72 73 |
# File 'lib/raw/compiler/filter/morph.rb', line 69 def comment(c) unless Template.strip_xml_comments @buffer << "<!--#{c}-->" end end |
#doctype(name, pub_sys, long_name, uri) ⇒ Object
75 76 77 |
# File 'lib/raw/compiler/filter/morph.rb', line 75 def doctype(name, pub_sys, long_name, uri) @buffer << "<!DOCTYPE #{name} #{pub_sys} #{long_name} #{uri}>\n" end |
#emit_end(name) ⇒ Object
84 85 86 |
# File 'lib/raw/compiler/filter/morph.rb', line 84 def emit_end(name) "</#{name}>" end |
#emit_start(name, attributes) ⇒ Object
79 80 81 82 |
# File 'lib/raw/compiler/filter/morph.rb', line 79 def emit_start(name, attributes) attrs = attributes.map{ |k, v| %|#{k}="#{v}"| }.join(' ') attrs.blank? ? "<#{name}>" : "<#{name} #{attrs}>" end |
#instruction(name, attributes) ⇒ Object
61 62 63 |
# File 'lib/raw/compiler/filter/morph.rb', line 61 def instruction(name, attributes) @buffer << "<?#{name}#{attributes}?>" end |
#tag_end(name) ⇒ Object
50 51 52 53 54 55 |
# File 'lib/raw/compiler/filter/morph.rb', line 50 def tag_end(name) morphers = @stack.pop morphers.reverse.each { |h| h.before_end(@buffer) } @buffer << emit_end(name) morphers.reverse.each { |h| h.after_end(@buffer) } end |
#tag_start(name, attributes) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/raw/compiler/filter/morph.rb', line 34 def tag_start(name, attributes) morphers = [] for morpher_class in @filter.morphers if attributes.has_key? morpher_class.key morphers << morpher_class.new(name, attributes) end end morphers.each { |h| h.before_start(@buffer) } @buffer << emit_start(name, attributes) morphers.each { |h| h.after_start(@buffer) } @stack.push(morphers) end |
#text(str) ⇒ Object
57 58 59 |
# File 'lib/raw/compiler/filter/morph.rb', line 57 def text(str) @buffer << str end |