Class: Wee::HtmlDocument

Inherits:
HtmlWriter show all
Defined in:
lib/wee/html_document.rb

Overview

Represents a complete HTML document.

Constant Summary

Constants inherited from HtmlWriter

Wee::HtmlWriter::CLOSING, Wee::HtmlWriter::SINGLE_CLOSING

Instance Attribute Summary

Attributes inherited from HtmlWriter

#port

Instance Method Summary collapse

Methods inherited from HtmlWriter

#encode_text, #end_tag, #single_tag, #start_tag, #text, #write

Constructor Details

#initializeHtmlDocument

Returns a new instance of HtmlDocument.



9
10
11
# File 'lib/wee/html_document.rb', line 9

def initialize
  super([])
end

Instance Method Details

#divert(tag, txt = nil, &block) ⇒ Object

Raises:

  • (ArgumentError)


17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/wee/html_document.rb', line 17

def divert(tag, txt=nil, &block)
  raise ArgumentError if txt and block
  @divert ||= {}

  unless divert = @divert[tag]
    @divert[tag] = divert = []
    @port << divert
  end

  if txt
    divert << txt
  end

  if block
    old_port = @port
    begin
      @port = divert
      block.call
    ensure
      @port = old_port
    end
  end
end

#setObject



13
14
15
# File 'lib/wee/html_document.rb', line 13

def set
  @set ||= {}
end

#to_sObject



41
42
43
# File 'lib/wee/html_document.rb', line 41

def to_s
  @port.join
end