Class: Herb::AST::ERBInNode

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

Overview

: type serialized_erb_in_node = { | tag_opening: Herb::Token?, | content: Herb::Token?, | tag_closing: Herb::Token?, | then_keyword: Herb::Location?, | 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, then_keyword, statements) ⇒ ERBInNode

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



4247
4248
4249
4250
4251
4252
4253
4254
# File 'lib/herb/ast/nodes.rb', line 4247

def initialize(type, location, errors, tag_opening, content, tag_closing, then_keyword, statements)
  super(type, location, errors)
  @tag_opening = tag_opening
  @content = content
  @tag_closing = tag_closing
  @then_keyword = then_keyword
  @statements = statements
end

Instance Attribute Details

#contentObject (readonly)

: Herb::Token?



4241
4242
4243
# File 'lib/herb/ast/nodes.rb', line 4241

def content
  @content
end

#statementsObject (readonly)

: Array



4244
4245
4246
# File 'lib/herb/ast/nodes.rb', line 4244

def statements
  @statements
end

#tag_closingObject (readonly)

: Herb::Token?



4242
4243
4244
# File 'lib/herb/ast/nodes.rb', line 4242

def tag_closing
  @tag_closing
end

#tag_openingObject (readonly)

: Herb::Token?



4240
4241
4242
# File 'lib/herb/ast/nodes.rb', line 4240

def tag_opening
  @tag_opening
end

#then_keywordObject (readonly)

: Herb::Location?



4243
4244
4245
# File 'lib/herb/ast/nodes.rb', line 4243

def then_keyword
  @then_keyword
end

Instance Method Details

#accept(visitor) ⇒ Object

: (Visitor) -> void



4268
4269
4270
# File 'lib/herb/ast/nodes.rb', line 4268

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

#child_nodesObject

: () -> Array



4273
4274
4275
# File 'lib/herb/ast/nodes.rb', line 4273

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

#compact_child_nodesObject

: () -> Array



4278
4279
4280
# File 'lib/herb/ast/nodes.rb', line 4278

def compact_child_nodes
  child_nodes.compact
end

#inspectObject

: () -> String



4283
4284
4285
# File 'lib/herb/ast/nodes.rb', line 4283

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

#to_hashObject

: () -> serialized_erb_in_node



4257
4258
4259
4260
4261
4262
4263
4264
4265
# File 'lib/herb/ast/nodes.rb', line 4257

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

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

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



4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
# File 'lib/herb/ast/nodes.rb', line 4288

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("├── then_keyword: ")
  output += then_keyword ? dimmed("(location: #{then_keyword.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