Class: Herb::AST::HTMLElementNode
- Includes:
- Colors
- Defined in:
- lib/herb/ast/nodes.rb,
ext/herb/nodes.c
Overview
: type serialized_html_element_node = { | open_tag: (Herb::AST::HTMLOpenTagNode | Herb::AST::HTMLConditionalOpenTagNode | Herb::AST::ERBOpenTagNode)?, | tag_name: Herb::Token?, | body: Array, | close_tag: (Herb::AST::HTMLCloseTagNode | Herb::AST::HTMLOmittedCloseTagNode | Herb::AST::HTMLVirtualCloseTagNode | Herb::AST::ERBEndNode)?, | is_void: bool, | element_source: String?, | }
Constant Summary
Constants included from Colors
Colors::CLEAR_SCREEN, Colors::HIDE_CURSOR, Colors::SHOW_CURSOR
Instance Attribute Summary collapse
-
#body ⇒ Object
readonly
: Array.
-
#close_tag ⇒ Object
readonly
: (Herb::AST::HTMLCloseTagNode | Herb::AST::HTMLOmittedCloseTagNode | Herb::AST::HTMLVirtualCloseTagNode | Herb::AST::ERBEndNode)?.
-
#element_source ⇒ Object
readonly
: String?.
-
#is_void ⇒ Object
readonly
: bool.
-
#open_tag ⇒ Object
readonly
: (Herb::AST::HTMLOpenTagNode | Herb::AST::HTMLConditionalOpenTagNode | Herb::AST::ERBOpenTagNode)?.
-
#tag_name ⇒ Object
readonly
: Herb::Token?.
Attributes inherited from Node
#errors, #location, #source, #type
Instance Method Summary collapse
-
#accept(visitor) ⇒ Object
: (Visitor) -> void.
-
#child_nodes ⇒ Object
: () -> Array.
-
#compact_child_nodes ⇒ Object
: () -> Array.
- #initialize(type, location, errors, open_tag, tag_name, body, close_tag, is_void, element_source) ⇒ HTMLElementNode constructor
-
#inspect ⇒ Object
: () -> String.
-
#to_hash ⇒ Object
: () -> serialized_html_element_node.
-
#tree_inspect(indent: 0, depth: 0, depth_limit: 10) ⇒ Object
: (?indent: Integer, ?depth: Integer, ?depth_limit: Integer) -> String.
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, open_tag, tag_name, body, close_tag, is_void, element_source) ⇒ HTMLElementNode
579 580 581 582 583 584 585 586 587 |
# File 'lib/herb/ast/nodes.rb', line 579 def initialize(type, location, errors, open_tag, tag_name, body, close_tag, is_void, element_source) super(type, location, errors) @open_tag = open_tag @tag_name = tag_name @body = body @close_tag = close_tag @is_void = is_void @element_source = element_source end |
Instance Attribute Details
#body ⇒ Object (readonly)
: Array
573 574 575 |
# File 'lib/herb/ast/nodes.rb', line 573 def body @body end |
#close_tag ⇒ Object (readonly)
: (Herb::AST::HTMLCloseTagNode | Herb::AST::HTMLOmittedCloseTagNode | Herb::AST::HTMLVirtualCloseTagNode | Herb::AST::ERBEndNode)?
574 575 576 |
# File 'lib/herb/ast/nodes.rb', line 574 def close_tag @close_tag end |
#element_source ⇒ Object (readonly)
: String?
576 577 578 |
# File 'lib/herb/ast/nodes.rb', line 576 def element_source @element_source end |
#is_void ⇒ Object (readonly)
: bool
575 576 577 |
# File 'lib/herb/ast/nodes.rb', line 575 def is_void @is_void end |
#open_tag ⇒ Object (readonly)
: (Herb::AST::HTMLOpenTagNode | Herb::AST::HTMLConditionalOpenTagNode | Herb::AST::ERBOpenTagNode)?
571 572 573 |
# File 'lib/herb/ast/nodes.rb', line 571 def open_tag @open_tag end |
#tag_name ⇒ Object (readonly)
: Herb::Token?
572 573 574 |
# File 'lib/herb/ast/nodes.rb', line 572 def tag_name @tag_name end |
Instance Method Details
#accept(visitor) ⇒ Object
: (Visitor) -> void
602 603 604 |
# File 'lib/herb/ast/nodes.rb', line 602 def accept(visitor) visitor.visit_html_element_node(self) end |
#child_nodes ⇒ Object
: () -> Array
607 608 609 |
# File 'lib/herb/ast/nodes.rb', line 607 def child_nodes [open_tag, *(body || []), close_tag] end |
#compact_child_nodes ⇒ Object
: () -> Array
612 613 614 |
# File 'lib/herb/ast/nodes.rb', line 612 def compact_child_nodes child_nodes.compact end |
#inspect ⇒ Object
: () -> String
617 618 619 |
# File 'lib/herb/ast/nodes.rb', line 617 def inspect tree_inspect.rstrip.gsub(/\s+$/, "") end |
#to_hash ⇒ Object
: () -> serialized_html_element_node
590 591 592 593 594 595 596 597 598 599 |
# File 'lib/herb/ast/nodes.rb', line 590 def to_hash super.merge({ open_tag: open_tag, tag_name: tag_name, body: body, close_tag: close_tag, is_void: is_void, element_source: element_source, }) #: Herb::serialized_html_element_node end |
#tree_inspect(indent: 0, depth: 0, depth_limit: 10) ⇒ Object
: (?indent: Integer, ?depth: Integer, ?depth_limit: Integer) -> String
622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 |
# File 'lib/herb/ast/nodes.rb', line 622 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("├── open_tag: ") if open_tag output += "\n" output += "│ └── " output += open_tag.tree_inspect(indent: indent, depth: depth + 1, depth_limit: depth_limit).gsub(/^/, " " * (indent + 1)).lstrip.gsub(/^/, "│ ").delete_prefix("│ ") else output += magenta("∅\n") end output += white("├── tag_name: ") output += tag_name ? tag_name.tree_inspect : magenta("∅") output += "\n" output += white("├── body: ") output += inspect_array(body, prefix: "│ ", indent: indent, depth: depth + 1, depth_limit: depth_limit) output += white("├── close_tag: ") if close_tag output += "\n" output += "│ └── " output += close_tag.tree_inspect(indent: indent, depth: depth + 1, depth_limit: depth_limit).gsub(/^/, " " * (indent + 1)).lstrip.gsub(/^/, "│ ").delete_prefix("│ ") else output += magenta("∅\n") end output += white("├── is_void: ") output += [true, false].include?(is_void) ? bold(magenta(is_void.to_s)) : magenta("∅") output += "\n" output += white("└── element_source: #{green(element_source.inspect)}\n") output += "\n" output.gsub(/^/, " " * indent) end |