Class: Herb::AST::ERBElseNode
- Includes:
- Colors
- Defined in:
- lib/herb/ast/nodes.rb,
ext/herb/nodes.c
Overview
: type serialized_erb_else_node = { | tag_opening: Herb::Token?, | content: Herb::Token?, | tag_closing: Herb::Token?, | 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?.
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, statements) ⇒ ERBElseNode constructor
-
#inspect ⇒ Object
: () -> String.
-
#to_hash ⇒ Object
: () -> serialized_erb_else_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, statements) ⇒ ERBElseNode
1914 1915 1916 1917 1918 1919 1920 |
# File 'lib/herb/ast/nodes.rb', line 1914 def initialize(type, location, errors, tag_opening, content, tag_closing, statements) super(type, location, errors) @tag_opening = tag_opening @content = content @tag_closing = tag_closing @statements = statements end |
Instance Attribute Details
#content ⇒ Object (readonly)
: Herb::Token?
1909 1910 1911 |
# File 'lib/herb/ast/nodes.rb', line 1909 def content @content end |
#statements ⇒ Object (readonly)
: Array
1911 1912 1913 |
# File 'lib/herb/ast/nodes.rb', line 1911 def statements @statements end |
#tag_closing ⇒ Object (readonly)
: Herb::Token?
1910 1911 1912 |
# File 'lib/herb/ast/nodes.rb', line 1910 def tag_closing @tag_closing end |
#tag_opening ⇒ Object (readonly)
: Herb::Token?
1908 1909 1910 |
# File 'lib/herb/ast/nodes.rb', line 1908 def tag_opening @tag_opening end |
Instance Method Details
#accept(visitor) ⇒ Object
: (Visitor) -> void
1933 1934 1935 |
# File 'lib/herb/ast/nodes.rb', line 1933 def accept(visitor) visitor.visit_erb_else_node(self) end |
#child_nodes ⇒ Object
: () -> Array
1938 1939 1940 |
# File 'lib/herb/ast/nodes.rb', line 1938 def child_nodes [*(statements || [])] end |
#compact_child_nodes ⇒ Object
: () -> Array
1943 1944 1945 |
# File 'lib/herb/ast/nodes.rb', line 1943 def compact_child_nodes child_nodes.compact end |
#inspect ⇒ Object
: () -> String
1948 1949 1950 |
# File 'lib/herb/ast/nodes.rb', line 1948 def inspect tree_inspect.rstrip.gsub(/\s+$/, "") end |
#to_hash ⇒ Object
: () -> serialized_erb_else_node
1923 1924 1925 1926 1927 1928 1929 1930 |
# File 'lib/herb/ast/nodes.rb', line 1923 def to_hash super.merge({ tag_opening: tag_opening, content: content, tag_closing: tag_closing, statements: statements, }) #: Herb::serialized_erb_else_node end |
#tree_inspect(indent: 0, depth: 0, depth_limit: 10) ⇒ Object
: (?indent: Integer, ?depth: Integer, ?depth_limit: Integer) -> String
1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 |
# File 'lib/herb/ast/nodes.rb', line 1953 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("└── statements: ") output += inspect_array(statements, prefix: " ", indent: indent, depth: depth + 1, depth_limit: depth_limit) output += "\n" output.gsub(/^/, " " * indent) end |