Class: Herb::AST::HTMLOpenTagNode
- Includes:
- Colors
- Defined in:
- lib/herb/ast/nodes.rb,
ext/herb/nodes.c
Overview
: type serialized_html_open_tag_node = { | tag_opening: Herb::Token?, | tag_name: Herb::Token?, | tag_closing: Herb::Token?, | children: Array, | is_void: bool, | }
Constant Summary
Constants included from Colors
Colors::CLEAR_SCREEN, Colors::HIDE_CURSOR, Colors::SHOW_CURSOR
Instance Attribute Summary collapse
-
#children ⇒ Object
readonly
: Array.
-
#is_void ⇒ Object
readonly
: bool.
-
#tag_closing ⇒ Object
readonly
: Herb::Token?.
-
#tag_name ⇒ Object
readonly
: Herb::Token?.
-
#tag_opening ⇒ Object
readonly
: Herb::Token?.
Attributes inherited from Node
#errors, #location, #source, #type
Instance Method Summary collapse
-
#accept(visitor) ⇒ Object
: (Visitor) -> void.
-
#child_nodes ⇒ Object
: () -> Array.
-
#compact_child_nodes ⇒ Object
: () -> Array.
- #initialize(type, location, errors, tag_opening, tag_name, tag_closing, children, is_void) ⇒ HTMLOpenTagNode constructor
-
#inspect ⇒ Object
: () -> String.
-
#to_hash ⇒ Object
: () -> serialized_html_open_tag_node.
-
#tree_inspect(indent: 0, depth: 0, depth_limit: 10) ⇒ Object
: (?indent: Integer, ?depth: Integer, ?depth_limit: Integer) -> String.
Methods included from Colors
bold, bright_magenta, cyan, dimmed, enabled?, fg, fg_bg, green, magenta, red, white, yellow
Methods inherited from Node
#class_name, #inspect_array, #inspect_errors, #node_name, #recursive_errors, #to_json
Constructor Details
#initialize(type, location, errors, tag_opening, tag_name, tag_closing, children, is_void) ⇒ HTMLOpenTagNode
186 187 188 189 190 191 192 193 |
# File 'lib/herb/ast/nodes.rb', line 186 def initialize(type, location, errors, tag_opening, tag_name, tag_closing, children, is_void) super(type, location, errors) @tag_opening = tag_opening @tag_name = tag_name @tag_closing = tag_closing @children = children @is_void = is_void end |
Instance Attribute Details
#children ⇒ Object (readonly)
: Array
182 183 184 |
# File 'lib/herb/ast/nodes.rb', line 182 def children @children end |
#is_void ⇒ Object (readonly)
: bool
183 184 185 |
# File 'lib/herb/ast/nodes.rb', line 183 def is_void @is_void end |
#tag_closing ⇒ Object (readonly)
: Herb::Token?
181 182 183 |
# File 'lib/herb/ast/nodes.rb', line 181 def tag_closing @tag_closing end |
#tag_name ⇒ Object (readonly)
: Herb::Token?
180 181 182 |
# File 'lib/herb/ast/nodes.rb', line 180 def tag_name @tag_name end |
#tag_opening ⇒ Object (readonly)
: Herb::Token?
179 180 181 |
# File 'lib/herb/ast/nodes.rb', line 179 def tag_opening @tag_opening end |
Instance Method Details
#accept(visitor) ⇒ Object
: (Visitor) -> void
207 208 209 |
# File 'lib/herb/ast/nodes.rb', line 207 def accept(visitor) visitor.visit_html_open_tag_node(self) end |
#child_nodes ⇒ Object
: () -> Array
212 213 214 |
# File 'lib/herb/ast/nodes.rb', line 212 def child_nodes [*(children || [])] end |
#compact_child_nodes ⇒ Object
: () -> Array
217 218 219 |
# File 'lib/herb/ast/nodes.rb', line 217 def compact_child_nodes child_nodes.compact end |
#inspect ⇒ Object
: () -> String
222 223 224 |
# File 'lib/herb/ast/nodes.rb', line 222 def inspect tree_inspect.rstrip.gsub(/\s+$/, "") end |
#to_hash ⇒ Object
: () -> serialized_html_open_tag_node
196 197 198 199 200 201 202 203 204 |
# File 'lib/herb/ast/nodes.rb', line 196 def to_hash super.merge({ tag_opening: tag_opening, tag_name: tag_name, tag_closing: tag_closing, children: children, is_void: is_void, }) #: Herb::serialized_html_open_tag_node end |
#tree_inspect(indent: 0, depth: 0, depth_limit: 10) ⇒ Object
: (?indent: Integer, ?depth: Integer, ?depth_limit: Integer) -> String
227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 |
# File 'lib/herb/ast/nodes.rb', line 227 def tree_inspect(indent: 0, depth: 0, depth_limit: 10) output = +"" output += white("@ #{bold(yellow(node_name.to_s))} #{dimmed("(location: #{location.tree_inspect})")}") output += "\n" if depth >= depth_limit output += dimmed("└── [depth limit reached ...]\n\n") return output.gsub(/^/, " " * indent) end output += inspect_errors(prefix: "│ ") output += white("├── tag_opening: ") output += tag_opening ? tag_opening.tree_inspect : magenta("∅") output += "\n" output += white("├── tag_name: ") output += tag_name ? tag_name.tree_inspect : magenta("∅") output += "\n" output += white("├── tag_closing: ") output += tag_closing ? tag_closing.tree_inspect : magenta("∅") output += "\n" output += white("├── children: ") output += inspect_array(children, prefix: "│ ", indent: indent, depth: depth + 1, depth_limit: depth_limit) output += white("└── is_void: ") output += [true, false].include?(is_void) ? bold(magenta(is_void.to_s)) : magenta("∅") output += "\n" output += "\n" output.gsub(/^/, " " * indent) end |