Class: Herb::Engine::DebugVisitor
- Inherits:
-
Visitor
- Object
- Visitor
- Herb::Engine::DebugVisitor
show all
- Defined in:
- lib/herb/engine/debug_visitor.rb
Instance Method Summary
collapse
Methods inherited from Visitor
#visit, #visit_all, #visit_cdata_node, #visit_child_nodes, #visit_erb_begin_node, #visit_erb_case_match_node, #visit_erb_case_node, #visit_erb_else_node, #visit_erb_end_node, #visit_erb_ensure_node, #visit_erb_for_node, #visit_erb_if_node, #visit_erb_in_node, #visit_erb_node, #visit_erb_open_tag_node, #visit_erb_render_node, #visit_erb_rescue_node, #visit_erb_strict_locals_node, #visit_erb_unless_node, #visit_erb_until_node, #visit_erb_when_node, #visit_erb_while_node, #visit_html_attribute_name_node, #visit_html_attribute_value_node, #visit_html_close_tag_node, #visit_html_conditional_element_node, #visit_html_conditional_open_tag_node, #visit_html_omitted_close_tag_node, #visit_html_open_tag_node, #visit_html_text_node, #visit_html_virtual_close_tag_node, #visit_literal_node, #visit_node, #visit_ruby_html_attributes_splat_node, #visit_ruby_literal_node, #visit_ruby_parameter_node, #visit_ruby_render_keywords_node, #visit_ruby_render_local_node, #visit_whitespace_node, #visit_xml_declaration_node
#erb_comment?, #erb_graphql?, #erb_outputs?, #inline_ruby_comment?
Constructor Details
#initialize(file_path: nil, project_path: nil) ⇒ DebugVisitor
Returns a new instance of DebugVisitor.
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
# File 'lib/herb/engine/debug_visitor.rb', line 7
def initialize(file_path: nil, project_path: nil)
super()
@filename = case file_path
when ::Pathname
file_path
when String
file_path.empty? ? nil : ::Pathname.new(file_path)
end
@project_path = case project_path
when ::Pathname
project_path
when String
::Pathname.new(project_path)
else
::Pathname.new(Dir.pwd)
end
@relative_file_path = calculate_relative_path
@top_level_elements = [] @element_stack = [] @erb_block_stack = [] @debug_attributes_applied = false
@in_attribute = false
@in_html_comment = false
@in_html_doctype = false
@erb_nodes_to_wrap = [] @top_level_elements = [] end
|
Instance Method Details
#visit_document_node(node) ⇒ Object
38
39
40
41
42
43
44
|
# File 'lib/herb/engine/debug_visitor.rb', line 38
def visit_document_node(node)
find_top_level_elements(node)
super
wrap_all_erb_nodes(node)
end
|
#visit_erb_block_node(node) ⇒ Object
89
90
91
92
93
|
# File 'lib/herb/engine/debug_visitor.rb', line 89
def visit_erb_block_node(node)
@erb_block_stack.push(node)
super
@erb_block_stack.pop
end
|
#visit_erb_content_node(node) ⇒ Object
75
76
77
78
79
80
81
82
83
|
# File 'lib/herb/engine/debug_visitor.rb', line 75
def visit_erb_content_node(node)
if !@in_attribute && !@in_html_comment && !@in_html_doctype && !in_excluded_context? && erb_output?(node.tag_opening.value)
code = node.content.value.strip
@erb_nodes_to_wrap << node unless complex_rails_helper?(code)
end
super
end
|
#visit_erb_yield_node(_node) ⇒ Object
85
86
87
|
# File 'lib/herb/engine/debug_visitor.rb', line 85
def visit_erb_yield_node(_node)
nil
end
|
#visit_html_attribute_node(node) ⇒ Object
57
58
59
60
61
|
# File 'lib/herb/engine/debug_visitor.rb', line 57
def visit_html_attribute_node(node)
@in_attribute = true
super
@in_attribute = false
end
|
63
64
65
66
67
|
# File 'lib/herb/engine/debug_visitor.rb', line 63
def (node)
@in_html_comment = true
super
@in_html_comment = false
end
|
#visit_html_doctype_node(node) ⇒ Object
69
70
71
72
73
|
# File 'lib/herb/engine/debug_visitor.rb', line 69
def visit_html_doctype_node(node)
@in_html_doctype = true
super
@in_html_doctype = false
end
|
#visit_html_element_node(node) ⇒ Object
46
47
48
49
50
51
52
53
54
55
|
# File 'lib/herb/engine/debug_visitor.rb', line 46
def visit_html_element_node(node)
tag_name = node.tag_name&.value&.downcase
@element_stack.push(tag_name) if tag_name
add_debug_attributes_to_element(node.open_tag) if should_add_debug_attributes_to_element?(node.open_tag)
super
@element_stack.pop if tag_name
end
|