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 |
# File 'lib/upkeep/herb/template_manifest.rb', line 141 def initialize(path:, source:) super() @path = path @frontend_tag_plan = [] @render_nodes = [] @helper_lowered_elements = [] @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
151 152 153 |
# File 'lib/upkeep/herb/template_manifest.rb', line 151 def root_shape @root_shape || EMPTY_ROOT_SHAPE end |
#visit_document_node(node) ⇒ Object
155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 |
# File 'lib/upkeep/herb/template_manifest.rb', line 155 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, multi_root: root_elements.size > 1 } if root_shape.fetch(:single_root) partial_template? ? plan_fragment_root_tag(root_elements.first) : plan_page_root_tag(root_elements.first) end super end |
#visit_erb_render_node(node) ⇒ Object
174 175 176 177 178 179 180 181 182 |
# File 'lib/upkeep/herb/template_manifest.rb', line 174 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) super end |
#visit_html_element_node(node) ⇒ Object
184 185 186 187 188 189 190 191 192 193 194 |
# File 'lib/upkeep/herb/template_manifest.rb', line 184 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 super end |