Class: Herb::AST::ERBCaseNode
- Includes:
- Colors
- Defined in:
- lib/herb/ast/nodes.rb,
ext/herb/nodes.c
Overview
Constant Summary
Constants included from Colors
Colors::CLEAR_SCREEN, Colors::HIDE_CURSOR, Colors::SHOW_CURSOR
Instance Attribute Summary collapse
-
#children ⇒ Object
readonly
: Array.
-
#conditions ⇒ Object
readonly
: Array.
-
#content ⇒ Object
readonly
: Herb::Token?.
-
#else_clause ⇒ Object
readonly
: Herb::AST::ERBElseNode?.
-
#end_node ⇒ Object
readonly
: Herb::AST::ERBEndNode?.
-
#prism_node ⇒ Object
readonly
: String?.
-
#tag_closing ⇒ 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.
-
#deserialized_prism_node ⇒ Object
: () -> Prism::node?.
- #initialize(type, location, errors, tag_opening, content, tag_closing, children, prism_node, conditions, else_clause, end_node) ⇒ ERBCaseNode constructor
-
#inspect ⇒ Object
: () -> String.
-
#to_hash ⇒ Object
: () -> serialized_erb_case_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, children, prism_node, conditions, else_clause, end_node) ⇒ ERBCaseNode
2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 |
# File 'lib/herb/ast/nodes.rb', line 2404 def initialize(type, location, errors, tag_opening, content, tag_closing, children, prism_node, conditions, else_clause, end_node) super(type, location, errors) @tag_opening = tag_opening @content = content @tag_closing = tag_closing @children = children @prism_node = prism_node @conditions = conditions @else_clause = else_clause @end_node = end_node end |
Instance Attribute Details
#children ⇒ Object (readonly)
: Array
2397 2398 2399 |
# File 'lib/herb/ast/nodes.rb', line 2397 def children @children end |
#conditions ⇒ Object (readonly)
: Array
2399 2400 2401 |
# File 'lib/herb/ast/nodes.rb', line 2399 def conditions @conditions end |
#content ⇒ Object (readonly)
: Herb::Token?
2395 2396 2397 |
# File 'lib/herb/ast/nodes.rb', line 2395 def content @content end |
#else_clause ⇒ Object (readonly)
: Herb::AST::ERBElseNode?
2400 2401 2402 |
# File 'lib/herb/ast/nodes.rb', line 2400 def else_clause @else_clause end |
#end_node ⇒ Object (readonly)
: Herb::AST::ERBEndNode?
2401 2402 2403 |
# File 'lib/herb/ast/nodes.rb', line 2401 def end_node @end_node end |
#prism_node ⇒ Object (readonly)
: String?
2398 2399 2400 |
# File 'lib/herb/ast/nodes.rb', line 2398 def prism_node @prism_node end |
#tag_closing ⇒ Object (readonly)
: Herb::Token?
2396 2397 2398 |
# File 'lib/herb/ast/nodes.rb', line 2396 def tag_closing @tag_closing end |
#tag_opening ⇒ Object (readonly)
: Herb::Token?
2394 2395 2396 |
# File 'lib/herb/ast/nodes.rb', line 2394 def tag_opening @tag_opening end |
Instance Method Details
#accept(visitor) ⇒ Object
: (Visitor) -> void
2447 2448 2449 |
# File 'lib/herb/ast/nodes.rb', line 2447 def accept(visitor) visitor.visit_erb_case_node(self) end |
#child_nodes ⇒ Object
: () -> Array
2452 2453 2454 |
# File 'lib/herb/ast/nodes.rb', line 2452 def child_nodes [*(children || []), *(conditions || []), else_clause, end_node] end |
#compact_child_nodes ⇒ Object
: () -> Array
2457 2458 2459 |
# File 'lib/herb/ast/nodes.rb', line 2457 def compact_child_nodes child_nodes.compact end |
#deserialized_prism_node ⇒ Object
: () -> Prism::node?
2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 |
# File 'lib/herb/ast/nodes.rb', line 2417 def deserialized_prism_node prism_node = @prism_node return nil unless prism_node return nil unless source begin require "prism" rescue LoadError warn "The 'prism' gem is required to deserialize Prism nodes. Add it to your Gemfile or install it with: gem install prism" return nil end Prism.load(source, prism_node).value end |
#inspect ⇒ Object
: () -> String
2462 2463 2464 |
# File 'lib/herb/ast/nodes.rb', line 2462 def inspect tree_inspect.rstrip.gsub(/\s+$/, "") end |
#to_hash ⇒ Object
: () -> serialized_erb_case_node
2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 |
# File 'lib/herb/ast/nodes.rb', line 2433 def to_hash super.merge({ tag_opening: tag_opening, content: content, tag_closing: tag_closing, children: children, prism_node: prism_node, conditions: conditions, else_clause: else_clause, end_node: end_node, }) #: Herb::serialized_erb_case_node end |
#tree_inspect(indent: 0, depth: 0, depth_limit: 10) ⇒ Object
: (?indent: Integer, ?depth: Integer, ?depth_limit: Integer) -> String
2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 |
# File 'lib/herb/ast/nodes.rb', line 2467 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("├── children: ") output += inspect_array(children, prefix: "│ ", indent: indent, depth: depth + 1, depth_limit: depth_limit) if prism_node && source output += white("├── prism_node: ") output += Herb::PrismInspect.inspect_prism_serialized(prism_node, source, "│ ") output += "\n" end output += white("├── conditions: ") output += inspect_array(conditions, prefix: "│ ", indent: indent, depth: depth + 1, depth_limit: depth_limit) output += white("├── else_clause: ") if else_clause output += "\n" output += "│ └── " output += else_clause.tree_inspect(indent: indent, depth: depth + 1, depth_limit: depth_limit).gsub(/^/, " " * (indent + 1)).lstrip.gsub(/^/, "│ ").delete_prefix("│ ") else output += magenta("∅\n") end output += white("└── end_node: ") if end_node output += "\n" output += " └── " output += end_node.tree_inspect(indent: indent, depth: depth + 1, depth_limit: depth_limit).gsub(/^/, " " * (indent + 1)).lstrip.gsub(/^/, " ").delete_prefix(" ") else output += magenta("∅\n") end output += "\n" output.gsub(/^/, " " * indent) end |