Class: Herb::AST::HTMLCloseTagNode

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

Overview

: type serialized_html_close_tag_node = { | tag_opening: Herb::Token?, | tag_name: Herb::Token?, | children: Array?, | tag_closing: Herb::Token?, | }

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, tag_name, children, tag_closing) ⇒ HTMLCloseTagNode

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



360
361
362
363
364
365
366
# File 'lib/herb/ast/nodes.rb', line 360

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

Instance Attribute Details

#childrenObject (readonly)

: Array?



356
357
358
# File 'lib/herb/ast/nodes.rb', line 356

def children
  @children
end

#tag_closingObject (readonly)

: Herb::Token?



357
358
359
# File 'lib/herb/ast/nodes.rb', line 357

def tag_closing
  @tag_closing
end

#tag_nameObject (readonly)

: Herb::Token?



355
356
357
# File 'lib/herb/ast/nodes.rb', line 355

def tag_name
  @tag_name
end

#tag_openingObject (readonly)

: Herb::Token?



354
355
356
# File 'lib/herb/ast/nodes.rb', line 354

def tag_opening
  @tag_opening
end

Instance Method Details

#accept(visitor) ⇒ Object

: (Visitor) -> void



379
380
381
# File 'lib/herb/ast/nodes.rb', line 379

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

#child_nodesObject

: () -> Array



384
385
386
# File 'lib/herb/ast/nodes.rb', line 384

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

#compact_child_nodesObject

: () -> Array



389
390
391
# File 'lib/herb/ast/nodes.rb', line 389

def compact_child_nodes
  child_nodes.compact
end

#inspectObject

: () -> String



394
395
396
# File 'lib/herb/ast/nodes.rb', line 394

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

#to_hashObject

: () -> serialized_html_close_tag_node



369
370
371
372
373
374
375
376
# File 'lib/herb/ast/nodes.rb', line 369

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

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

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



399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
# File 'lib/herb/ast/nodes.rb', line 399

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("├── 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 += white("└── tag_closing: ")
  output += tag_closing ? tag_closing.tree_inspect : magenta("")
  output += "\n"
  output += "\n"

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