Class: Herb::AST::HTMLDoctypeNode

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

Overview

: type serialized_html_doctype_node = { | tag_opening: 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, children, tag_closing) ⇒ HTMLDoctypeNode

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



1411
1412
1413
1414
1415
1416
# File 'lib/herb/ast/nodes.rb', line 1411

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

Instance Attribute Details

#childrenObject (readonly)

: Array



1407
1408
1409
# File 'lib/herb/ast/nodes.rb', line 1407

def children
  @children
end

#tag_closingObject (readonly)

: Herb::Token?



1408
1409
1410
# File 'lib/herb/ast/nodes.rb', line 1408

def tag_closing
  @tag_closing
end

#tag_openingObject (readonly)

: Herb::Token?



1406
1407
1408
# File 'lib/herb/ast/nodes.rb', line 1406

def tag_opening
  @tag_opening
end

Instance Method Details

#accept(visitor) ⇒ Object

: (Visitor) -> void



1428
1429
1430
# File 'lib/herb/ast/nodes.rb', line 1428

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

#child_nodesObject

: () -> Array



1433
1434
1435
# File 'lib/herb/ast/nodes.rb', line 1433

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

#compact_child_nodesObject

: () -> Array



1438
1439
1440
# File 'lib/herb/ast/nodes.rb', line 1438

def compact_child_nodes
  child_nodes.compact
end

#inspectObject

: () -> String



1443
1444
1445
# File 'lib/herb/ast/nodes.rb', line 1443

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

#to_hashObject

: () -> serialized_html_doctype_node



1419
1420
1421
1422
1423
1424
1425
# File 'lib/herb/ast/nodes.rb', line 1419

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

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

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



1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
# File 'lib/herb/ast/nodes.rb', line 1448

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("├── 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