Class: RuBB::Node::Styled
- Inherits:
-
RuBB::Node
- Object
- RuBB::Node
- RuBB::Node::Styled
- Defined in:
- lib/rubb/node/styled.rb
Instance Attribute Summary collapse
-
#html_tag_name ⇒ Object
Returns the value of attribute html_tag_name.
-
#style_hash ⇒ Object
Returns the value of attribute style_hash.
Attributes inherited from RuBB::Node
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Styled
constructor
A new instance of Styled.
- #to_html ⇒ Object
Methods inherited from RuBB::Node
Constructor Details
#initialize(options = {}) ⇒ Styled
Returns a new instance of Styled.
7 8 9 10 11 |
# File 'lib/rubb/node/styled.rb', line 7 def initialize(={}) super() @style_hash = [:style_hash] || {} @html_tag_name = [:html_tag_name] || 'span' end |
Instance Attribute Details
#html_tag_name ⇒ Object
Returns the value of attribute html_tag_name.
5 6 7 |
# File 'lib/rubb/node/styled.rb', line 5 def html_tag_name @html_tag_name end |
#style_hash ⇒ Object
Returns the value of attribute style_hash.
4 5 6 |
# File 'lib/rubb/node/styled.rb', line 4 def style_hash @style_hash end |
Instance Method Details
#to_html ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/rubb/node/styled.rb', line 13 def to_html html = "<#{@html_tag_name} style=\"" @style_hash.each do |k,v| if(v) # if v is not nil v = v[/\A([^;]*);/,1] if v.include?(';') # ignore semicolons and any trailing text html += "#{k}: #{v};" end end html += '">' @children.each do |child| html += child ? child.to_html : '' end html + "</#{@html_tag_name}>" end |