Class: Browser::DOM::Builder

Inherits:
Object
  • Object
show all
Defined in:
opal/browser/dom/builder.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(document, &block) ⇒ Builder

Returns a new instance of Builder.



41
42
43
44
45
# File 'opal/browser/dom/builder.rb', line 41

def initialize(document, &block)
  @document = document
  @builder  = Paggio::HTML.new(&block)
  @roots    = @builder.each.map { |e| Builder.build(self, e) }
end

Instance Attribute Details

#documentObject (readonly)

Returns the value of attribute document.



39
40
41
# File 'opal/browser/dom/builder.rb', line 39

def document
  @document
end

#elementObject (readonly)

Returns the value of attribute element.



39
40
41
# File 'opal/browser/dom/builder.rb', line 39

def element
  @element
end

Class Method Details

.build(builder, item) ⇒ Object

Raises:

  • (ArgumentError)


29
30
31
32
33
34
35
36
37
# File 'opal/browser/dom/builder.rb', line 29

def self.build(builder, item)
  to_h.each {|klass, block|
    if klass === item
      return block.call(builder, item)
    end
  }

  raise ArgumentError, "cannot build unknown item #{item}"
end

.for(klass, &block) ⇒ Object



21
22
23
24
25
26
27
# File 'opal/browser/dom/builder.rb', line 21

def self.for(klass, &block)
  if block
    to_h[klass] = block
  else
    to_h[klass]
  end
end

.to_hObject



17
18
19
# File 'opal/browser/dom/builder.rb', line 17

def self.to_h
  @builders ||= {}
end

Instance Method Details

#to_aObject



47
48
49
# File 'opal/browser/dom/builder.rb', line 47

def to_a
  @roots
end