Class: Herb::AST::HTMLConditionalElementNode

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

Overview

: type serialized_html_conditional_element_node = { | condition: String?, | open_conditional: (Herb::AST::ERBIfNode | Herb::AST::ERBUnlessNode)?, | open_tag: Herb::AST::HTMLOpenTagNode?, | body: Array, | close_tag: (Herb::AST::HTMLCloseTagNode | Herb::AST::HTMLOmittedCloseTagNode)?, | close_conditional: (Herb::AST::ERBIfNode | Herb::AST::ERBUnlessNode)?, | tag_name: Herb::Token?, | element_source: String?, | }

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, condition, open_conditional, open_tag, body, close_tag, close_conditional, tag_name, element_source) ⇒ HTMLConditionalElementNode

: (String, Location, Array, String, (Herb::AST::ERBIfNode | Herb::AST::ERBUnlessNode), Herb::AST::HTMLOpenTagNode, Array, (Herb::AST::HTMLCloseTagNode | Herb::AST::HTMLOmittedCloseTagNode), (Herb::AST::ERBIfNode | Herb::AST::ERBUnlessNode), Herb::Token, String) -> void



690
691
692
693
694
695
696
697
698
699
700
# File 'lib/herb/ast/nodes.rb', line 690

def initialize(type, location, errors, condition, open_conditional, open_tag, body, close_tag, close_conditional, tag_name, element_source)
  super(type, location, errors)
  @condition = condition&.force_encoding("utf-8")
  @open_conditional = open_conditional
  @open_tag = open_tag
  @body = body
  @close_tag = close_tag
  @close_conditional = close_conditional
  @tag_name = tag_name
  @element_source = element_source
end

Instance Attribute Details

#bodyObject (readonly)

: Array



683
684
685
# File 'lib/herb/ast/nodes.rb', line 683

def body
  @body
end

#close_conditionalObject (readonly)

: (Herb::AST::ERBIfNode | Herb::AST::ERBUnlessNode)?



685
686
687
# File 'lib/herb/ast/nodes.rb', line 685

def close_conditional
  @close_conditional
end

#close_tagObject (readonly)

: (Herb::AST::HTMLCloseTagNode | Herb::AST::HTMLOmittedCloseTagNode)?



684
685
686
# File 'lib/herb/ast/nodes.rb', line 684

def close_tag
  @close_tag
end

#conditionObject (readonly)

: String?



680
681
682
# File 'lib/herb/ast/nodes.rb', line 680

def condition
  @condition
end

#element_sourceObject (readonly)

: String?



687
688
689
# File 'lib/herb/ast/nodes.rb', line 687

def element_source
  @element_source
end

#open_conditionalObject (readonly)

: (Herb::AST::ERBIfNode | Herb::AST::ERBUnlessNode)?



681
682
683
# File 'lib/herb/ast/nodes.rb', line 681

def open_conditional
  @open_conditional
end

#open_tagObject (readonly)

: Herb::AST::HTMLOpenTagNode?



682
683
684
# File 'lib/herb/ast/nodes.rb', line 682

def open_tag
  @open_tag
end

#tag_nameObject (readonly)

: Herb::Token?



686
687
688
# File 'lib/herb/ast/nodes.rb', line 686

def tag_name
  @tag_name
end

Instance Method Details

#accept(visitor) ⇒ Object

: (Visitor) -> void



717
718
719
# File 'lib/herb/ast/nodes.rb', line 717

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

#child_nodesObject

: () -> Array



722
723
724
# File 'lib/herb/ast/nodes.rb', line 722

def child_nodes
  [open_conditional, open_tag, *(body || []), close_tag, close_conditional]
end

#compact_child_nodesObject

: () -> Array



727
728
729
# File 'lib/herb/ast/nodes.rb', line 727

def compact_child_nodes
  child_nodes.compact
end

#inspectObject

: () -> String



732
733
734
# File 'lib/herb/ast/nodes.rb', line 732

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

#to_hashObject

: () -> serialized_html_conditional_element_node



703
704
705
706
707
708
709
710
711
712
713
714
# File 'lib/herb/ast/nodes.rb', line 703

def to_hash
  super.merge({
    condition: condition,
    open_conditional: open_conditional,
    open_tag: open_tag,
    body: body,
    close_tag: close_tag,
    close_conditional: close_conditional,
    tag_name: tag_name,
    element_source: element_source,
  }) #: Herb::serialized_html_conditional_element_node
end

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

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



737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
# File 'lib/herb/ast/nodes.rb', line 737

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("├── condition: ") + green("#{condition.inspect}\n")
  output += white("├── open_conditional: ")
  if open_conditional
    output += "\n"
    output += "│   └── "
    output += open_conditional.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("├── 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("├── 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("├── close_conditional: ")
  if close_conditional
    output += "\n"
    output += "│   └── "
    output += close_conditional.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("└── element_source: #{green(element_source.inspect)}\n")
  output += "\n"

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