Class: Lapillus::HtmlVisitor

Inherits:
Object
  • Object
show all
Defined in:
lib/lapillus/html_visitor.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(webpage) ⇒ HtmlVisitor

Returns a new instance of HtmlVisitor.



21
22
23
24
# File 'lib/lapillus/html_visitor.rb', line 21

def initialize(webpage)
  @container_output = REXML::Document.new
  @current_container = webpage
end

Instance Attribute Details

#container_outputObject

INFO: there are 4 elements to remember INFO: 1 current template html element INFO: 2 current output html element INFO: 3 current component to render INFO: 4 current container to get components from



18
19
20
# File 'lib/lapillus/html_visitor.rb', line 18

def container_output
  @container_output
end

#current_containerObject

Returns the value of attribute current_container.



19
20
21
# File 'lib/lapillus/html_visitor.rb', line 19

def current_container
  @current_container
end

Instance Method Details

#visit_comment(comment) ⇒ Object



41
42
43
44
# File 'lib/lapillus/html_visitor.rb', line 41

def visit_comment(comment)
  new_comment = REXML::Comment.new(comment)
  container_output.add(new_comment)  
end

#visit_element(element) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/lapillus/html_visitor.rb', line 26

def visit_element(element)
  return if element.name=="fragment"
  #puts "rendering: #{element.name}"
  component_id = element.attributes['lapillus:id']
  if !component_id.nil?
    child_component = current_container[component_id]
  else
    child_component = NullComponent.new          
  end

  child_component.render_container(self, element)
end

#visit_text(text) ⇒ Object



38
39
40
# File 'lib/lapillus/html_visitor.rb', line 38

def visit_text(text)
  container_output.add_text(text.value)
end