Class: Herb::AST::ERBWhileNode
- Includes:
- Colors
- Defined in:
- lib/herb/ast/nodes.rb,
ext/herb/nodes.c
Overview
: type serialized_erb_while_node = { | tag_opening: Herb::Token?, | content: Herb::Token?, | tag_closing: Herb::Token?, | prism_node: String?, | statements: Array, | end_node: Herb::AST::ERBEndNode?, | }
Constant Summary
Constants included from Colors
Colors::CLEAR_SCREEN, Colors::HIDE_CURSOR, Colors::SHOW_CURSOR
Instance Attribute Summary collapse
-
#content ⇒ Object
readonly
: Herb::Token?.
-
#end_node ⇒ Object
readonly
: Herb::AST::ERBEndNode?.
-
#prism_node ⇒ Object
readonly
: String?.
-
#statements ⇒ Object
readonly
: Array.
-
#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, prism_node, statements, end_node) ⇒ ERBWhileNode constructor
-
#inspect ⇒ Object
: () -> String.
-
#to_hash ⇒ Object
: () -> serialized_erb_while_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, prism_node, statements, end_node) ⇒ ERBWhileNode
2680 2681 2682 2683 2684 2685 2686 2687 2688 |
# File 'lib/herb/ast/nodes.rb', line 2680 def initialize(type, location, errors, tag_opening, content, tag_closing, prism_node, statements, end_node) super(type, location, errors) @tag_opening = tag_opening @content = content @tag_closing = tag_closing @prism_node = prism_node @statements = statements @end_node = end_node end |
Instance Attribute Details
#content ⇒ Object (readonly)
: Herb::Token?
2673 2674 2675 |
# File 'lib/herb/ast/nodes.rb', line 2673 def content @content end |
#end_node ⇒ Object (readonly)
: Herb::AST::ERBEndNode?
2677 2678 2679 |
# File 'lib/herb/ast/nodes.rb', line 2677 def end_node @end_node end |
#prism_node ⇒ Object (readonly)
: String?
2675 2676 2677 |
# File 'lib/herb/ast/nodes.rb', line 2675 def prism_node @prism_node end |
#statements ⇒ Object (readonly)
: Array
2676 2677 2678 |
# File 'lib/herb/ast/nodes.rb', line 2676 def statements @statements end |
#tag_closing ⇒ Object (readonly)
: Herb::Token?
2674 2675 2676 |
# File 'lib/herb/ast/nodes.rb', line 2674 def tag_closing @tag_closing end |
#tag_opening ⇒ Object (readonly)
: Herb::Token?
2672 2673 2674 |
# File 'lib/herb/ast/nodes.rb', line 2672 def tag_opening @tag_opening end |
Instance Method Details
#accept(visitor) ⇒ Object
: (Visitor) -> void
2719 2720 2721 |
# File 'lib/herb/ast/nodes.rb', line 2719 def accept(visitor) visitor.visit_erb_while_node(self) end |
#child_nodes ⇒ Object
: () -> Array
2724 2725 2726 |
# File 'lib/herb/ast/nodes.rb', line 2724 def child_nodes [*(statements || []), end_node] end |
#compact_child_nodes ⇒ Object
: () -> Array
2729 2730 2731 |
# File 'lib/herb/ast/nodes.rb', line 2729 def compact_child_nodes child_nodes.compact end |
#deserialized_prism_node ⇒ Object
: () -> Prism::node?
2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 |
# File 'lib/herb/ast/nodes.rb', line 2691 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
2734 2735 2736 |
# File 'lib/herb/ast/nodes.rb', line 2734 def inspect tree_inspect.rstrip.gsub(/\s+$/, "") end |
#to_hash ⇒ Object
: () -> serialized_erb_while_node
2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 |
# File 'lib/herb/ast/nodes.rb', line 2707 def to_hash super.merge({ tag_opening: tag_opening, content: content, tag_closing: tag_closing, prism_node: prism_node, statements: statements, end_node: end_node, }) #: Herb::serialized_erb_while_node end |
#tree_inspect(indent: 0, depth: 0, depth_limit: 10) ⇒ Object
: (?indent: Integer, ?depth: Integer, ?depth_limit: Integer) -> String
2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 |
# File 'lib/herb/ast/nodes.rb', line 2739 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" if prism_node && source output += white("├── prism_node: ") output += Herb::PrismInspect.inspect_prism_serialized(prism_node, source, "│ ") output += "\n" end output += white("├── statements: ") output += inspect_array(statements, prefix: "│ ", indent: indent, depth: depth + 1, depth_limit: depth_limit) 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 |