Class: SyntaxTree::ERB::HtmlNode::OpeningTag

Inherits:
Element
  • Object
show all
Defined in:
lib/syntax_tree/erb/nodes.rb

Overview

The opening tag of an element. It contains the opening character (<), the name of the element, any optional attributes, and the closing token (either > or />).

Instance Attribute Summary collapse

Attributes inherited from Element

#location, #new_line

Instance Method Summary collapse

Methods inherited from Element

#without_new_line

Methods inherited from Node

#format, #pretty_print, #skip?, #without_new_line

Constructor Details

#initialize(opening:, name:, attributes:, closing:, new_line:, location:) ⇒ OpeningTag

Returns a new instance of OpeningTag.



171
172
173
174
175
176
177
178
179
180
181
182
183
184
# File 'lib/syntax_tree/erb/nodes.rb', line 171

def initialize(
  opening:,
  name:,
  attributes:,
  closing:,
  new_line:,
  location:
)
  super(new_line: new_line, location: location)
  @opening = opening
  @name = name
  @attributes = attributes
  @closing = closing
end

Instance Attribute Details

#attributesObject (readonly)

Returns the value of attribute attributes.



169
170
171
# File 'lib/syntax_tree/erb/nodes.rb', line 169

def attributes
  @attributes
end

#closingObject (readonly)

Returns the value of attribute closing.



169
170
171
# File 'lib/syntax_tree/erb/nodes.rb', line 169

def closing
  @closing
end

#nameObject (readonly)

Returns the value of attribute name.



169
170
171
# File 'lib/syntax_tree/erb/nodes.rb', line 169

def name
  @name
end

#openingObject (readonly)

Returns the value of attribute opening.



169
170
171
# File 'lib/syntax_tree/erb/nodes.rb', line 169

def opening
  @opening
end

Instance Method Details

#accept(visitor) ⇒ Object



186
187
188
# File 'lib/syntax_tree/erb/nodes.rb', line 186

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

#child_nodesObject Also known as: deconstruct



190
191
192
# File 'lib/syntax_tree/erb/nodes.rb', line 190

def child_nodes
  [opening, name, *attributes, closing]
end

#deconstruct_keys(keys) ⇒ Object



200
201
202
203
204
205
206
207
# File 'lib/syntax_tree/erb/nodes.rb', line 200

def deconstruct_keys(keys)
  super.merge(
    opening: opening,
    name: name,
    attributes: attributes,
    closing: closing
  )
end

#is_void_element?Boolean

Returns:

  • (Boolean)


194
195
196
# File 'lib/syntax_tree/erb/nodes.rb', line 194

def is_void_element?
  HTML_VOID_ELEMENTS.include?(name.value)
end