Class: Herb::AST::ERBWhenNode
- Includes:
- Colors
- Defined in:
- lib/herb/ast/nodes.rb,
ext/herb/nodes.c
Overview
: type serialized_erb_when_node = { | tag_opening: Herb::Token?, | content: Herb::Token?, | tag_closing: Herb::Token?, | then_keyword: Herb::Location?, | statements: Array, | }
Constant Summary
Constants included from Colors
Colors::CLEAR_SCREEN, Colors::HIDE_CURSOR, Colors::SHOW_CURSOR
Instance Attribute Summary collapse
-
#content ⇒ Object
readonly
: Herb::Token?.
-
#statements ⇒ Object
readonly
: Array.
-
#tag_closing ⇒ Object
readonly
: Herb::Token?.
-
#tag_opening ⇒ Object
readonly
: Herb::Token?.
-
#then_keyword ⇒ Object
readonly
: Herb::Location?.
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, content, tag_closing, then_keyword, statements) ⇒ ERBWhenNode constructor
-
#inspect ⇒ Object
: () -> String.
-
#to_hash ⇒ Object
: () -> serialized_erb_when_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, content, tag_closing, then_keyword, statements) ⇒ ERBWhenNode
2306 2307 2308 2309 2310 2311 2312 2313 |
# File 'lib/herb/ast/nodes.rb', line 2306 def initialize(type, location, errors, tag_opening, content, tag_closing, then_keyword, statements) super(type, location, errors) @tag_opening = tag_opening @content = content @tag_closing = tag_closing @then_keyword = then_keyword @statements = statements end |
Instance Attribute Details
#content ⇒ Object (readonly)
: Herb::Token?
2300 2301 2302 |
# File 'lib/herb/ast/nodes.rb', line 2300 def content @content end |
#statements ⇒ Object (readonly)
: Array
2303 2304 2305 |
# File 'lib/herb/ast/nodes.rb', line 2303 def statements @statements end |
#tag_closing ⇒ Object (readonly)
: Herb::Token?
2301 2302 2303 |
# File 'lib/herb/ast/nodes.rb', line 2301 def tag_closing @tag_closing end |
#tag_opening ⇒ Object (readonly)
: Herb::Token?
2299 2300 2301 |
# File 'lib/herb/ast/nodes.rb', line 2299 def tag_opening @tag_opening end |
#then_keyword ⇒ Object (readonly)
: Herb::Location?
2302 2303 2304 |
# File 'lib/herb/ast/nodes.rb', line 2302 def then_keyword @then_keyword end |
Instance Method Details
#accept(visitor) ⇒ Object
: (Visitor) -> void
2327 2328 2329 |
# File 'lib/herb/ast/nodes.rb', line 2327 def accept(visitor) visitor.visit_erb_when_node(self) end |
#child_nodes ⇒ Object
: () -> Array
2332 2333 2334 |
# File 'lib/herb/ast/nodes.rb', line 2332 def child_nodes [*(statements || [])] end |
#compact_child_nodes ⇒ Object
: () -> Array
2337 2338 2339 |
# File 'lib/herb/ast/nodes.rb', line 2337 def compact_child_nodes child_nodes.compact end |
#inspect ⇒ Object
: () -> String
2342 2343 2344 |
# File 'lib/herb/ast/nodes.rb', line 2342 def inspect tree_inspect.rstrip.gsub(/\s+$/, "") end |
#to_hash ⇒ Object
: () -> serialized_erb_when_node
2316 2317 2318 2319 2320 2321 2322 2323 2324 |
# File 'lib/herb/ast/nodes.rb', line 2316 def to_hash super.merge({ tag_opening: tag_opening, content: content, tag_closing: tag_closing, then_keyword: then_keyword, statements: statements, }) #: Herb::serialized_erb_when_node end |
#tree_inspect(indent: 0, depth: 0, depth_limit: 10) ⇒ Object
: (?indent: Integer, ?depth: Integer, ?depth_limit: Integer) -> String
2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 |
# File 'lib/herb/ast/nodes.rb', line 2347 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("├── content: ") output += content ? content.tree_inspect : magenta("∅") output += "\n" output += white("├── tag_closing: ") output += tag_closing ? tag_closing.tree_inspect : magenta("∅") output += "\n" output += white("├── then_keyword: ") output += then_keyword ? dimmed("(location: #{then_keyword.tree_inspect})") : magenta("∅") output += "\n" output += white("└── statements: ") output += inspect_array(statements, prefix: " ", indent: indent, depth: depth + 1, depth_limit: depth_limit) output += "\n" output.gsub(/^/, " " * indent) end |