Class: Rhtml::Html
- Inherits:
-
Object
- Object
- Rhtml::Html
- Defined in:
- lib/rhtml/html.rb
Instance Method Summary collapse
-
#initialize(content = '', indent = 0, &b) ⇒ Html
constructor
A new instance of Html.
- #raw!(string = '') ⇒ Object
- #tag!(tag_name, ps = {}, str = nil, &b) ⇒ Object
- #to_s ⇒ Object
- #void_tag!(tag_name, ps = {}) ⇒ Object
Constructor Details
#initialize(content = '', indent = 0, &b) ⇒ Html
Returns a new instance of Html.
3 4 5 6 7 8 9 |
# File 'lib/rhtml/html.rb', line 3 def initialize(content='', indent=0, &b) @indent = 0 @content = content @cls = nil @id = nil @content << instance_eval(&b) if block_given? end |
Instance Method Details
#raw!(string = '') ⇒ Object
46 47 48 |
# File 'lib/rhtml/html.rb', line 46 def raw! string='' @content << string.to_s << "\n" end |
#tag!(tag_name, ps = {}, str = nil, &b) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/rhtml/html.rb', line 11 def tag!(tag_name, ps={}, str=nil, &b) str, ps = ps, {} if ps.is_a? String ps[:class] = @cls if @cls ps[:id] = @id if @id @content << Rhtml.tag_open(tag_name, ps, @indent) @cls = @id = nil @indent += 1 if str @content << INDENT * @indent << str << "\n" elsif block_given? ret = instance_eval &b @content << INDENT * @indent << ret.to_s << "\n" if ret.is_a?(String) end @indent -= 1 @content << Rhtml.tag_close(tag_name, @indent) self end |
#to_s ⇒ Object
50 51 52 |
# File 'lib/rhtml/html.rb', line 50 def to_s @content end |
#void_tag!(tag_name, ps = {}) ⇒ Object
29 30 31 32 |
# File 'lib/rhtml/html.rb', line 29 def void_tag!(tag_name, ps={}) @content << Rhtml.void_tag(tag_name, ps, @indent) self end |