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(x) ⇒ DomRender
constructor
A new instance of DomRender.
- #render(x) ⇒ Object
- #render_all(x) ⇒ Object
Constructor Details
#initialize(x) ⇒ DomRender
Returns a new instance of DomRender.
12 13 14 15 16 17 18 19 20 21 |
# File 'lib/dom_render.rb', line 12 def initialize(x) doc = if x.kind_of? Rexle then x else Rexle.new x.gsub(/\n/,'') end @to_a = render doc.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
23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/dom_render.rb', line 23 def render(x) style = fetch_style(x.attributes) if x.attributes.has_key? :style args = [x] args.concat([x.attributes, style]) r = method(x.name.to_sym).call(*args) if r.last.empty? then r[0..-2] else r end end |
#render_all(x) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/dom_render.rb', line 38 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 |