Class: SyntaxTree::ERB::PrettyPrint
- Inherits:
-
Visitor
- Object
- Visitor
- Visitor
- SyntaxTree::ERB::PrettyPrint
show all
- Defined in:
- lib/syntax_tree/erb/pretty_print.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods inherited from Visitor
#visit, #visit_statements
Constructor Details
Returns a new instance of PrettyPrint.
8
9
10
|
# File 'lib/syntax_tree/erb/pretty_print.rb', line 8
def initialize(q)
@q = q
end
|
Instance Attribute Details
#q ⇒ Object
Returns the value of attribute q.
6
7
8
|
# File 'lib/syntax_tree/erb/pretty_print.rb', line 6
def q
@q
end
|
Instance Method Details
#visit_attribute(node) ⇒ Object
120
121
122
|
# File 'lib/syntax_tree/erb/pretty_print.rb', line 120
def visit_attribute(node)
visit_node("attribute", node)
end
|
#visit_block(node) ⇒ Object
22
23
24
|
# File 'lib/syntax_tree/erb/pretty_print.rb', line 22
def visit_block(node)
visit_node(node.class.to_s, node)
end
|
#visit_char_data(node) ⇒ Object
130
131
132
|
# File 'lib/syntax_tree/erb/pretty_print.rb', line 130
def visit_char_data(node)
visit_node("char_data", node)
end
|
#visit_closing_tag(node) ⇒ Object
Visit an HtmlNode::ClosingTag node.
37
38
39
|
# File 'lib/syntax_tree/erb/pretty_print.rb', line 37
def visit_closing_tag(node)
visit_node("closing_tag", node)
end
|
#visit_doctype(node) ⇒ Object
151
152
153
|
# File 'lib/syntax_tree/erb/pretty_print.rb', line 151
def visit_doctype(node)
visit_node("doctype", node)
end
|
#visit_document(node) ⇒ Object
18
19
20
|
# File 'lib/syntax_tree/erb/pretty_print.rb', line 18
def visit_document(node)
visit_node("document", node)
end
|
#visit_erb(node) ⇒ Object
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
|
# File 'lib/syntax_tree/erb/pretty_print.rb', line 42
def visit_erb(node)
q.group do
q.text("(erb")
q.nest(2) do
q.breakable
visit(node.opening_tag)
if node.keyword
q.breakable
visit(node.keyword)
end
if node.content
q.breakable
q.text("content")
end
q.breakable
visit(node.closing_tag)
end
q.breakable("")
q.text(")")
end
end
|
#visit_erb_block(node) ⇒ Object
65
66
67
68
69
70
71
72
73
74
75
76
77
|
# File 'lib/syntax_tree/erb/pretty_print.rb', line 65
def visit_erb_block(node)
q.group do
q.text("(erb_block")
q.nest(2) do
q.breakable
q.seplist(node.elements) { |child_node| visit(child_node) }
end
q.breakable
visit(node.closing)
q.breakable("")
q.text(")")
end
end
|
#visit_erb_case(node) ⇒ Object
102
103
104
|
# File 'lib/syntax_tree/erb/pretty_print.rb', line 102
def visit_erb_case(node)
visit_erb_if(node, "erb_case")
end
|
#visit_erb_case_when(node) ⇒ Object
106
107
108
|
# File 'lib/syntax_tree/erb/pretty_print.rb', line 106
def visit_erb_case_when(node)
visit_erb_if(node, "erb_when")
end
|
#visit_erb_close(node) ⇒ Object
138
139
140
|
# File 'lib/syntax_tree/erb/pretty_print.rb', line 138
def visit_erb_close(node)
visit(node.closing)
end
|
159
160
161
|
# File 'lib/syntax_tree/erb/pretty_print.rb', line 159
def (node)
visit_node("erb_comment", node)
end
|
#visit_erb_content(node) ⇒ Object
Visit an ErbContent node.
115
116
117
|
# File 'lib/syntax_tree/erb/pretty_print.rb', line 115
def visit_erb_content(node)
q.pp(node.value)
end
|
#visit_erb_do_close(node) ⇒ Object
142
143
144
|
# File 'lib/syntax_tree/erb/pretty_print.rb', line 142
def visit_erb_do_close(node)
visit_node("erb_do_close", node)
end
|
#visit_erb_else(node) ⇒ Object
98
99
100
|
# File 'lib/syntax_tree/erb/pretty_print.rb', line 98
def visit_erb_else(node)
visit_erb_if(node, "erb_else")
end
|
#visit_erb_elsif(node) ⇒ Object
94
95
96
|
# File 'lib/syntax_tree/erb/pretty_print.rb', line 94
def visit_erb_elsif(node)
visit_erb_if(node, "erb_elsif")
end
|
#visit_erb_end(node) ⇒ Object
110
111
112
|
# File 'lib/syntax_tree/erb/pretty_print.rb', line 110
def visit_erb_end(node)
q.pp("(erb_end)")
end
|
#visit_erb_if(node, key = "erb_if") ⇒ Object
79
80
81
82
83
84
85
86
87
88
89
90
91
92
|
# File 'lib/syntax_tree/erb/pretty_print.rb', line 79
def visit_erb_if(node, key = "erb_if")
q.group do
q.text("(")
visit(node.opening)
q.nest(2) do
q.breakable()
q.seplist(node.child_nodes) { |child_node| visit(child_node) }
end
q.breakable
visit(node.closing)
q.breakable("")
q.text(")")
end
end
|
#visit_erb_yield(node) ⇒ Object
146
147
148
|
# File 'lib/syntax_tree/erb/pretty_print.rb', line 146
def visit_erb_yield(node)
visit_node("erb_yield", node)
end
|
#visit_html(node) ⇒ Object
27
28
29
|
# File 'lib/syntax_tree/erb/pretty_print.rb', line 27
def visit_html(node)
visit_node("html", node)
end
|
155
156
157
|
# File 'lib/syntax_tree/erb/pretty_print.rb', line 155
def (node)
visit_node("html_comment", node)
end
|
#visit_html_string(node) ⇒ Object
125
126
127
|
# File 'lib/syntax_tree/erb/pretty_print.rb', line 125
def visit_html_string(node)
visit_node("html_string", node)
end
|
#visit_new_line(node) ⇒ Object
134
135
136
|
# File 'lib/syntax_tree/erb/pretty_print.rb', line 134
def visit_new_line(node)
node.count > 1 ? q.text("(new_line blank)") : q.text("(new_line)")
end
|
#visit_opening_tag(node) ⇒ Object
Visit an HtmlNode::OpeningTag node.
32
33
34
|
# File 'lib/syntax_tree/erb/pretty_print.rb', line 32
def visit_opening_tag(node)
visit_node("opening_tag", node)
end
|
#visit_token(node) ⇒ Object
13
14
15
|
# File 'lib/syntax_tree/erb/pretty_print.rb', line 13
def visit_token(node)
q.pp(node.value)
end
|