Class: Lapillus::HtmlVisitor
Instance Attribute Summary collapse
-
#container_output ⇒ Object
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.
-
#current_container ⇒ Object
Returns the value of attribute current_container.
Instance Method Summary collapse
-
#initialize(webpage) ⇒ HtmlVisitor
constructor
A new instance of HtmlVisitor.
- #visit_comment(comment) ⇒ Object
- #visit_element(element) ⇒ Object
- #visit_text(text) ⇒ Object
Constructor Details
#initialize(webpage) ⇒ HtmlVisitor
Returns a new instance of HtmlVisitor.
37 38 39 40 |
# File 'lib/lapillus/html_visitor.rb', line 37 def initialize(webpage) @container_output = REXML::Document.new @current_container = webpage end |
Instance Attribute Details
#container_output ⇒ Object
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
34 35 36 |
# File 'lib/lapillus/html_visitor.rb', line 34 def container_output @container_output end |
#current_container ⇒ Object
Returns the value of attribute current_container.
35 36 37 |
# File 'lib/lapillus/html_visitor.rb', line 35 def current_container @current_container end |
Instance Method Details
#visit_comment(comment) ⇒ Object
57 58 59 60 |
# File 'lib/lapillus/html_visitor.rb', line 57 def visit_comment(comment) new_comment = REXML::Comment.new(comment) container_output.add(new_comment) end |
#visit_element(element) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/lapillus/html_visitor.rb', line 42 def visit_element(element) return if element.name=="fragment" component_id = element.attributes['lapillus:id'] if !component_id.nil? child_component = current_container[component_id] #puts "rendering: #{element.name} with #{component_id} -> #{child_component.class} from #{current_container.class}" else child_component = NullComponent.new end child_component.render_container(self, element) end |
#visit_text(text) ⇒ Object
54 55 56 |
# File 'lib/lapillus/html_visitor.rb', line 54 def visit_text(text) container_output.add_text(text.value) end |