Class: Herb::AST::ERBEnsureNode

Inherits:
Node
  • Object
show all
Includes:
Colors
Defined in:
lib/herb/ast/nodes.rb,
ext/herb/nodes.c

Overview

: type serialized_erb_ensure_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

Attributes inherited from Node

#errors, #location, #source, #type

Instance Method Summary collapse

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) ⇒ ERBEnsureNode

: (String, Location, Array, Herb::Token, Herb::Token, Herb::Token, Array) -> void



3139
3140
3141
3142
3143
3144
3145
# File 'lib/herb/ast/nodes.rb', line 3139

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

#contentObject (readonly)

: Herb::Token?



3134
3135
3136
# File 'lib/herb/ast/nodes.rb', line 3134

def content
  @content
end

#statementsObject (readonly)

: Array



3136
3137
3138
# File 'lib/herb/ast/nodes.rb', line 3136

def statements
  @statements
end

#tag_closingObject (readonly)

: Herb::Token?



3135
3136
3137
# File 'lib/herb/ast/nodes.rb', line 3135

def tag_closing
  @tag_closing
end

#tag_openingObject (readonly)

: Herb::Token?



3133
3134
3135
# File 'lib/herb/ast/nodes.rb', line 3133

def tag_opening
  @tag_opening
end

Instance Method Details

#accept(visitor) ⇒ Object

: (Visitor) -> void



3158
3159
3160
# File 'lib/herb/ast/nodes.rb', line 3158

def accept(visitor)
  visitor.visit_erb_ensure_node(self)
end

#child_nodesObject

: () -> Array



3163
3164
3165
# File 'lib/herb/ast/nodes.rb', line 3163

def child_nodes
  [*(statements || [])]
end

#compact_child_nodesObject

: () -> Array



3168
3169
3170
# File 'lib/herb/ast/nodes.rb', line 3168

def compact_child_nodes
  child_nodes.compact
end

#inspectObject

: () -> String



3173
3174
3175
# File 'lib/herb/ast/nodes.rb', line 3173

def inspect
  tree_inspect.rstrip.gsub(/\s+$/, "")
end

#to_hashObject

: () -> serialized_erb_ensure_node



3148
3149
3150
3151
3152
3153
3154
3155
# File 'lib/herb/ast/nodes.rb', line 3148

def to_hash
  super.merge({
    tag_opening: tag_opening,
    content: content,
    tag_closing: tag_closing,
    statements: statements,
  }) #: Herb::serialized_erb_ensure_node
end

#tree_inspect(indent: 0, depth: 0, depth_limit: 10) ⇒ Object

: (?indent: Integer, ?depth: Integer, ?depth_limit: Integer) -> String



3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
# File 'lib/herb/ast/nodes.rb', line 3178

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