Class: Herb::AST::HTMLCommentNode

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

Overview

: type serialized_html_comment_node = { | comment_start: Herb::Token?, | children: Array, | comment_end: 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, #self?.bold, #self?.bright_magenta, #self?.cyan, #self?.dimmed, #self?.enabled?, #self?.fg, #self?.fg_bg, #self?.green, #self?.magenta, #self?.red, #self?.white, #self?.yellow, white, yellow

Methods inherited from Node

#class_name, #inspect_array, #inspect_errors, #node_name, #recursive_errors, #to_json

Constructor Details

#initialize(type, location, errors, comment_start, children, comment_end) ⇒ HTMLCommentNode

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

Parameters:



1333
1334
1335
1336
1337
1338
# File 'lib/herb/ast/nodes.rb', line 1333

def initialize(type, location, errors, comment_start, children, comment_end)
  super(type, location, errors)
  @comment_start = comment_start
  @children = children
  @comment_end = comment_end
end

Instance Attribute Details

#childrenArray[Herb::AST::Node] (readonly)

: Array

Returns:



1329
1330
1331
# File 'lib/herb/ast/nodes.rb', line 1329

def children
  @children
end

#comment_endHerb::Token? (readonly)

: Herb::Token?

Returns:



1330
1331
1332
# File 'lib/herb/ast/nodes.rb', line 1330

def comment_end
  @comment_end
end

#comment_startHerb::Token? (readonly)

: Herb::Token?

Returns:



1328
1329
1330
# File 'lib/herb/ast/nodes.rb', line 1328

def comment_start
  @comment_start
end

Instance Method Details

#accept(visitor) ⇒ void

This method returns an undefined value.

: (Visitor) -> void

Parameters:



1350
1351
1352
# File 'lib/herb/ast/nodes.rb', line 1350

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

#child_nodesArray[Herb::AST::Node?]

: () -> Array

Returns:



1355
1356
1357
# File 'lib/herb/ast/nodes.rb', line 1355

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

#compact_child_nodesArray[Herb::AST::Node]

: () -> Array

Returns:



1360
1361
1362
# File 'lib/herb/ast/nodes.rb', line 1360

def compact_child_nodes
  child_nodes.compact
end

#inspectString

: () -> String

Returns:

  • (String)


1365
1366
1367
# File 'lib/herb/ast/nodes.rb', line 1365

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

#to_hashserialized_html_comment_node

: () -> serialized_html_comment_node

Returns:

  • (serialized_html_comment_node)


1341
1342
1343
1344
1345
1346
1347
# File 'lib/herb/ast/nodes.rb', line 1341

def to_hash
  super.merge({
    comment_start: comment_start,
    children: children,
    comment_end: comment_end,
  }) #: Herb::serialized_html_comment_node
end

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

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

Parameters:

  • indent: (Integer) (defaults to: 0)
  • depth: (Integer) (defaults to: 0)
  • depth_limit: (Integer) (defaults to: 10)

Returns:

  • (String)


1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
# File 'lib/herb/ast/nodes.rb', line 1370

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

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