Class: Herb::AST::HTMLAttributeNode

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

Overview

: type serialized_html_attribute_node = { | name: Herb::AST::HTMLAttributeNameNode?, | equals: Herb::Token?, | value: Herb::AST::HTMLAttributeValueNode?, | }

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, name, equals, value) ⇒ HTMLAttributeNode

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



958
959
960
961
962
963
# File 'lib/herb/ast/nodes.rb', line 958

def initialize(type, location, errors, name, equals, value)
  super(type, location, errors)
  @name = name
  @equals = equals
  @value = value
end

Instance Attribute Details

#equalsObject (readonly)

: Herb::Token?



954
955
956
# File 'lib/herb/ast/nodes.rb', line 954

def equals
  @equals
end

#nameObject (readonly)

: Herb::AST::HTMLAttributeNameNode?



953
954
955
# File 'lib/herb/ast/nodes.rb', line 953

def name
  @name
end

#valueObject (readonly)

: Herb::AST::HTMLAttributeValueNode?



955
956
957
# File 'lib/herb/ast/nodes.rb', line 955

def value
  @value
end

Instance Method Details

#accept(visitor) ⇒ Object

: (Visitor) -> void



975
976
977
# File 'lib/herb/ast/nodes.rb', line 975

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

#child_nodesObject

: () -> Array



980
981
982
# File 'lib/herb/ast/nodes.rb', line 980

def child_nodes
  [name, value]
end

#compact_child_nodesObject

: () -> Array



985
986
987
# File 'lib/herb/ast/nodes.rb', line 985

def compact_child_nodes
  child_nodes.compact
end

#inspectObject

: () -> String



990
991
992
# File 'lib/herb/ast/nodes.rb', line 990

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

#to_hashObject

: () -> serialized_html_attribute_node



966
967
968
969
970
971
972
# File 'lib/herb/ast/nodes.rb', line 966

def to_hash
  super.merge({
    name: name,
    equals: equals,
    value: value,
  }) #: Herb::serialized_html_attribute_node
end

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

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



995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
# File 'lib/herb/ast/nodes.rb', line 995

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("├── name: ")
  if name
    output += "\n"
    output += "│   └── "
    output += name.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("├── equals: ")
  output += equals ? equals.tree_inspect : magenta("")
  output += "\n"
  output += white("└── value: ")
  if value
    output += "\n"
    output += "    └── "
    output += value.tree_inspect(indent: indent, depth: depth + 1, depth_limit: depth_limit).gsub(/^/, "    " * (indent + 1)).lstrip.gsub(/^/, "    ").delete_prefix("    ")
  else
    output += magenta("∅\n")
  end
  output += "\n"

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