Class: SyntaxTree::ERB::HtmlNode

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

Overview

An element is a child of the document. It contains an opening tag, any optional content within the tag, and a closing tag. It can also potentially contain an opening tag that self-closes, in which case the content and closing tag will be nil.

Defined Under Namespace

Classes: ClosingTag, OpeningTag

Instance Attribute Summary

Attributes inherited from Block

#closing, #elements, #location, #opening

Instance Method Summary collapse

Methods inherited from Block

#child_nodes, #deconstruct_keys, #initialize

Methods inherited from Node

#format, #pretty_print, #skip?

Constructor Details

This class inherits a constructor from SyntaxTree::ERB::Block

Instance Method Details

#accept(visitor) ⇒ Object



270
271
272
# File 'lib/syntax_tree/erb/nodes.rb', line 270

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

#new_lineObject

The HTML-closing tag is responsible for new lines after the node.



266
267
268
# File 'lib/syntax_tree/erb/nodes.rb', line 266

def new_line
  closing.nil? ? opening.new_line : closing&.new_line
end

#without_new_lineObject



256
257
258
259
260
261
262
263
# File 'lib/syntax_tree/erb/nodes.rb', line 256

def without_new_line
  self.class.new(
    **deconstruct_keys([]).merge(
      opening: closing.nil? ? opening.without_new_line : opening,
      closing: closing&.without_new_line
    )
  )
end