Class: Upkeep::HerbSupport::TemplateManifest::Visitor
- Inherits:
-
Herb::Visitor
- Object
- Herb::Visitor
- Upkeep::HerbSupport::TemplateManifest::Visitor
- Defined in:
- lib/upkeep/herb/template_manifest.rb
Instance Attribute Summary collapse
-
#frontend_tag_plan ⇒ Object
readonly
Returns the value of attribute frontend_tag_plan.
-
#helper_lowered_elements ⇒ Object
readonly
Returns the value of attribute helper_lowered_elements.
-
#render_nodes ⇒ Object
readonly
Returns the value of attribute render_nodes.
Instance Method Summary collapse
-
#initialize(path:, source:) ⇒ Visitor
constructor
A new instance of Visitor.
- #root_shape ⇒ Object
- #visit_document_node(node) ⇒ Object
- #visit_erb_render_node(node) ⇒ Object
- #visit_html_element_node(node) ⇒ Object
Constructor Details
#initialize(path:, source:) ⇒ Visitor
Returns a new instance of Visitor.
141 142 143 144 145 146 147 148 149 150 |
# File 'lib/upkeep/herb/template_manifest.rb', line 141 def initialize(path:, source:) super() @path = path @frontend_tag_plan = [] @render_nodes = [] @helper_lowered_elements = [] @html_stack = [] @root_shape = nil @line_offsets = build_line_offsets(source) end |
Instance Attribute Details
#frontend_tag_plan ⇒ Object (readonly)
Returns the value of attribute frontend_tag_plan.
139 140 141 |
# File 'lib/upkeep/herb/template_manifest.rb', line 139 def frontend_tag_plan @frontend_tag_plan end |
#helper_lowered_elements ⇒ Object (readonly)
Returns the value of attribute helper_lowered_elements.
139 140 141 |
# File 'lib/upkeep/herb/template_manifest.rb', line 139 def helper_lowered_elements @helper_lowered_elements end |
#render_nodes ⇒ Object (readonly)
Returns the value of attribute render_nodes.
139 140 141 |
# File 'lib/upkeep/herb/template_manifest.rb', line 139 def render_nodes @render_nodes end |
Instance Method Details
#root_shape ⇒ Object
152 153 154 |
# File 'lib/upkeep/herb/template_manifest.rb', line 152 def root_shape @root_shape || EMPTY_ROOT_SHAPE end |
#visit_document_node(node) ⇒ Object
156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 |
# File 'lib/upkeep/herb/template_manifest.rb', line 156 def visit_document_node(node) significant_children = node.children.reject { |child| insignificant_document_child?(child) } root_elements = significant_children.select { |child| html_element?(child) } @root_shape = { significant_children: significant_children.size, root_elements: root_elements.size, root_types: significant_children.map { |child| child.class.name }, single_root: significant_children.size == 1 && root_elements.size == 1, single_root_element: root_elements.size == 1, multi_root: root_elements.size > 1 } if partial_template? plan_fragment_root_tag(root_elements.first) if root_shape.fetch(:single_root) elsif root_shape.fetch(:single_root_element) # A page template's recorded frame target needs a matching DOM marker so it can be # resolved during full-page rerender. Page templates routinely carry non-element # siblings such as `content_for`/`yield :head` ERB statements that produce no enclosing # DOM, so anchor the page-frame marker to the single root element rather than requiring # the element to be the only significant child. plan_page_root_tag(root_elements.first) end super end |
#visit_erb_render_node(node) ⇒ Object
183 184 185 186 187 188 189 190 191 |
# File 'lib/upkeep/herb/template_manifest.rb', line 183 def visit_erb_render_node(node) keywords = node.keywords render_node = render_node_payload(node, keywords) @render_nodes << render_node @frontend_tag_plan << render_site_tag(render_node) if render_node.fetch(:render_site_container) super end |
#visit_html_element_node(node) ⇒ Object
193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 |
# File 'lib/upkeep/herb/template_manifest.rb', line 193 def visit_html_element_node(node) if node.respond_to?(:element_source) && node.element_source && node.element_source != "HTML" @helper_lowered_elements << { location: location_payload(node.location), tag_name: token_value(node.tag_name), element_source: node.element_source } end @html_stack.push(node) begin super ensure @html_stack.pop end end |