Class: Herb::AST::ERBBlockNode
- Includes:
- Colors
- Defined in:
- lib/herb/ast/nodes.rb,
ext/herb/nodes.c
Overview
: type serialized_erb_block_node = { | tag_opening: Herb::Token?, | content: Herb::Token?, | tag_closing: Herb::Token?, | prism_node: String?, | body: Array, | block_arguments: Array?, | rescue_clause: Herb::AST::ERBRescueNode?, | else_clause: Herb::AST::ERBElseNode?, | ensure_clause: Herb::AST::ERBEnsureNode?, | end_node: Herb::AST::ERBEndNode?, | }
Constant Summary
Constants included from Colors
Colors::CLEAR_SCREEN, Colors::HIDE_CURSOR, Colors::SHOW_CURSOR
Instance Attribute Summary collapse
-
#block_arguments ⇒ Object
readonly
: Array?.
-
#body ⇒ Object
readonly
: Array.
-
#content ⇒ Object
readonly
: Herb::Token?.
-
#else_clause ⇒ Object
readonly
: Herb::AST::ERBElseNode?.
-
#end_node ⇒ Object
readonly
: Herb::AST::ERBEndNode?.
-
#ensure_clause ⇒ Object
readonly
: Herb::AST::ERBEnsureNode?.
-
#prism_node ⇒ Object
readonly
: String?.
-
#rescue_clause ⇒ Object
readonly
: Herb::AST::ERBRescueNode?.
-
#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, body, block_arguments, rescue_clause, else_clause, ensure_clause, end_node) ⇒ ERBBlockNode constructor
-
#inspect ⇒ Object
: () -> String.
-
#to_hash ⇒ Object
: () -> serialized_erb_block_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, body, block_arguments, rescue_clause, else_clause, ensure_clause, end_node) ⇒ ERBBlockNode
2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 |
# File 'lib/herb/ast/nodes.rb', line 2152 def initialize(type, location, errors, tag_opening, content, tag_closing, prism_node, body, block_arguments, rescue_clause, else_clause, ensure_clause, end_node) super(type, location, errors) @tag_opening = tag_opening @content = content @tag_closing = tag_closing @prism_node = prism_node @body = body @block_arguments = block_arguments @rescue_clause = rescue_clause @else_clause = else_clause @ensure_clause = ensure_clause @end_node = end_node end |
Instance Attribute Details
#block_arguments ⇒ Object (readonly)
: Array?
2145 2146 2147 |
# File 'lib/herb/ast/nodes.rb', line 2145 def block_arguments @block_arguments end |
#body ⇒ Object (readonly)
: Array
2144 2145 2146 |
# File 'lib/herb/ast/nodes.rb', line 2144 def body @body end |
#content ⇒ Object (readonly)
: Herb::Token?
2141 2142 2143 |
# File 'lib/herb/ast/nodes.rb', line 2141 def content @content end |
#else_clause ⇒ Object (readonly)
: Herb::AST::ERBElseNode?
2147 2148 2149 |
# File 'lib/herb/ast/nodes.rb', line 2147 def else_clause @else_clause end |
#end_node ⇒ Object (readonly)
: Herb::AST::ERBEndNode?
2149 2150 2151 |
# File 'lib/herb/ast/nodes.rb', line 2149 def end_node @end_node end |
#ensure_clause ⇒ Object (readonly)
: Herb::AST::ERBEnsureNode?
2148 2149 2150 |
# File 'lib/herb/ast/nodes.rb', line 2148 def ensure_clause @ensure_clause end |
#prism_node ⇒ Object (readonly)
: String?
2143 2144 2145 |
# File 'lib/herb/ast/nodes.rb', line 2143 def prism_node @prism_node end |
#rescue_clause ⇒ Object (readonly)
: Herb::AST::ERBRescueNode?
2146 2147 2148 |
# File 'lib/herb/ast/nodes.rb', line 2146 def rescue_clause @rescue_clause end |
#tag_closing ⇒ Object (readonly)
: Herb::Token?
2142 2143 2144 |
# File 'lib/herb/ast/nodes.rb', line 2142 def tag_closing @tag_closing end |
#tag_opening ⇒ Object (readonly)
: Herb::Token?
2140 2141 2142 |
# File 'lib/herb/ast/nodes.rb', line 2140 def tag_opening @tag_opening end |
Instance Method Details
#accept(visitor) ⇒ Object
: (Visitor) -> void
2199 2200 2201 |
# File 'lib/herb/ast/nodes.rb', line 2199 def accept(visitor) visitor.visit_erb_block_node(self) end |
#child_nodes ⇒ Object
: () -> Array
2204 2205 2206 |
# File 'lib/herb/ast/nodes.rb', line 2204 def child_nodes [*(body || []), *(block_arguments || []), rescue_clause, else_clause, ensure_clause, end_node] end |
#compact_child_nodes ⇒ Object
: () -> Array
2209 2210 2211 |
# File 'lib/herb/ast/nodes.rb', line 2209 def compact_child_nodes child_nodes.compact end |
#deserialized_prism_node ⇒ Object
: () -> Prism::node?
2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 |
# File 'lib/herb/ast/nodes.rb', line 2167 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
2214 2215 2216 |
# File 'lib/herb/ast/nodes.rb', line 2214 def inspect tree_inspect.rstrip.gsub(/\s+$/, "") end |
#to_hash ⇒ Object
: () -> serialized_erb_block_node
2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 |
# File 'lib/herb/ast/nodes.rb', line 2183 def to_hash super.merge({ tag_opening: tag_opening, content: content, tag_closing: tag_closing, prism_node: prism_node, body: body, block_arguments: block_arguments, rescue_clause: rescue_clause, else_clause: else_clause, ensure_clause: ensure_clause, end_node: end_node, }) #: Herb::serialized_erb_block_node end |
#tree_inspect(indent: 0, depth: 0, depth_limit: 10) ⇒ Object
: (?indent: Integer, ?depth: Integer, ?depth_limit: Integer) -> String
2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 |
# File 'lib/herb/ast/nodes.rb', line 2219 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("├── body: ") output += inspect_array(body, prefix: "│ ", indent: indent, depth: depth + 1, depth_limit: depth_limit) output += white("├── block_arguments: ") output += inspect_array(block_arguments, prefix: "│ ", indent: indent, depth: depth + 1, depth_limit: depth_limit) output += white("├── rescue_clause: ") if rescue_clause output += "\n" output += "│ └── " output += rescue_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("├── 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("├── ensure_clause: ") if ensure_clause output += "\n" output += "│ └── " output += ensure_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 |