Class: DomRender
- Inherits:
-
Object
- Object
- DomRender
- Defined in:
- lib/dom_render.rb
Instance Attribute Summary collapse
-
#to_a ⇒ Object
readonly
Returns the value of attribute to_a.
Instance Method Summary collapse
-
#initialize(s) ⇒ DomRender
constructor
A new instance of DomRender.
- #render(x) ⇒ Object
- #render_all(x) ⇒ Object
Constructor Details
#initialize(s) ⇒ DomRender
12 13 14 |
# File 'lib/dom_render.rb', line 12 def initialize(s) @to_a = render Rexle.new(s.gsub(/\n/,'')).root end |
Instance Attribute Details
#to_a ⇒ Object (readonly)
Returns the value of attribute to_a.
10 11 12 |
# File 'lib/dom_render.rb', line 10 def to_a @to_a end |
Instance Method Details
#render(x) ⇒ Object
16 17 18 19 20 21 22 23 24 25 |
# File 'lib/dom_render.rb', line 16 def render(x) r = method(x.name.to_sym).call(x) if r.last.empty? then r[0..-2] else r end end |
#render_all(x) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/dom_render.rb', line 27 def render_all(x) len = x.children.length - 1 x.children.map.with_index do |obj,i| if obj.is_a? String then i == 0 ? obj.lstrip.sub(/\s+$/,' ') : obj.rstrip.sub(/^\s+/,' ') elsif obj.is_a? Rexle::Element render obj end end end |