Class: Rhtml::Html

Inherits:
Object
  • Object
show all
Defined in:
lib/rhtml/html.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(content = '', indent = 0, &b) ⇒ Html

Returns a new instance of Html.



5
6
7
8
9
# File 'lib/rhtml/html.rb', line 5

def initialize(content='', indent=0, &b)
  @indent = 0
  @content = content
  @content << instance_eval(&b) if block_given?
end

Instance Attribute Details

#contentObject

Returns the value of attribute content.



3
4
5
# File 'lib/rhtml/html.rb', line 3

def content
  @content
end

#indentObject

Returns the value of attribute indent.



3
4
5
# File 'lib/rhtml/html.rb', line 3

def indent
  @indent
end

Instance Method Details

#raw!(string = '') ⇒ Object



43
44
45
# File 'lib/rhtml/html.rb', line 43

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
# File 'lib/rhtml/html.rb', line 11

def tag!(tag_name, ps={}, str=nil,  &b)
  str, ps = ps, {} if ps.is_a? String
  content << Rhtml.tag_open(tag_name, ps, indent)
  @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
  self.content << Rhtml.tag_close(tag_name, indent)
  self
end

#to_sObject



47
48
49
# File 'lib/rhtml/html.rb', line 47

def to_s
  content
end

#void_tag!(tag_name, ps = {}) ⇒ Object



26
27
28
29
# File 'lib/rhtml/html.rb', line 26

def void_tag!(tag_name, ps={})
  content << Rhtml.void_tag(tag_name, ps, indent)
  self
end