Class: Wizport::Html::Element

Inherits:
Object
  • Object
show all
Defined in:
lib/wizport/document/html/element.rb

Direct Known Subclasses

Document, Table, Text

Instance Method Summary collapse

Constructor Details

#initialize(html) ⇒ Element

Returns a new instance of Element.



9
10
11
# File 'lib/wizport/document/html/element.rb', line 9

def initialize(html)
  @html = html
end

Instance Method Details

#tag(name, *args) ⇒ Object

text = nil, options = {})



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/wizport/document/html/element.rb', line 13

def tag(name, *args) #text = nil, options = {})
  text = nil
  options = {}
  case args.size
    when 1
      if args.first.is_a?(Hash)
        options = args.first
      else
        text = args.first
      end
    when 2
      text = args.first
      options = args.last
  end
  @html.write '<'
  @html.write name
  options.each do |k, v|
    @html.write " #{k}='#{v}'"
  end
  @html.write '>'
  @html.write text if text
  yield if block_given?
  @html.write '</'
  @html.write name
  @html.write '>'
end