Class: Herb::AST::ERBOpenTagNode

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

Overview

: type serialized_erb_open_tag_node = { | tag_opening: Herb::Token?, | content: Herb::Token?, | tag_closing: Herb::Token?, | tag_name: Herb::Token?, | children: 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, tag_name, children) ⇒ ERBOpenTagNode

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



1182
1183
1184
1185
1186
1187
1188
1189
# File 'lib/herb/ast/nodes.rb', line 1182

def initialize(type, location, errors, tag_opening, content, tag_closing, tag_name, children)
  super(type, location, errors)
  @tag_opening = tag_opening
  @content = content
  @tag_closing = tag_closing
  @tag_name = tag_name
  @children = children
end

Instance Attribute Details

#childrenObject (readonly)

: Array



1179
1180
1181
# File 'lib/herb/ast/nodes.rb', line 1179

def children
  @children
end

#contentObject (readonly)

: Herb::Token?



1176
1177
1178
# File 'lib/herb/ast/nodes.rb', line 1176

def content
  @content
end

#tag_closingObject (readonly)

: Herb::Token?



1177
1178
1179
# File 'lib/herb/ast/nodes.rb', line 1177

def tag_closing
  @tag_closing
end

#tag_nameObject (readonly)

: Herb::Token?



1178
1179
1180
# File 'lib/herb/ast/nodes.rb', line 1178

def tag_name
  @tag_name
end

#tag_openingObject (readonly)

: Herb::Token?



1175
1176
1177
# File 'lib/herb/ast/nodes.rb', line 1175

def tag_opening
  @tag_opening
end

Instance Method Details

#accept(visitor) ⇒ Object

: (Visitor) -> void



1203
1204
1205
# File 'lib/herb/ast/nodes.rb', line 1203

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

#child_nodesObject

: () -> Array



1208
1209
1210
# File 'lib/herb/ast/nodes.rb', line 1208

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

#compact_child_nodesObject

: () -> Array



1213
1214
1215
# File 'lib/herb/ast/nodes.rb', line 1213

def compact_child_nodes
  child_nodes.compact
end

#inspectObject

: () -> String



1218
1219
1220
# File 'lib/herb/ast/nodes.rb', line 1218

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

#to_hashObject

: () -> serialized_erb_open_tag_node



1192
1193
1194
1195
1196
1197
1198
1199
1200
# File 'lib/herb/ast/nodes.rb', line 1192

def to_hash
  super.merge({
    tag_opening: tag_opening,
    content: content,
    tag_closing: tag_closing,
    tag_name: tag_name,
    children: children,
  }) #: Herb::serialized_erb_open_tag_node
end

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

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



1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
# File 'lib/herb/ast/nodes.rb', line 1223

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("├── tag_name: ")
  output += tag_name ? tag_name.tree_inspect : magenta("")
  output += "\n"
  output += white("└── children: ")
  output += inspect_array(children, prefix: "    ", indent: indent, depth: depth + 1, depth_limit: depth_limit)
  output += "\n"

  output.gsub(/^/, "    " * indent)
end