Class: SyntaxTree::ERB::ErbNode

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

Direct Known Subclasses

ErbEnd

Instance Attribute Summary collapse

Attributes inherited from Element

#location

Instance Method Summary collapse

Methods inherited from Node

#format, #pretty_print, #skip?

Constructor Details

#initialize(opening_tag:, keyword:, content:, closing_tag:, new_line:, location:) ⇒ ErbNode

Returns a new instance of ErbNode.



263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
# File 'lib/syntax_tree/erb/nodes.rb', line 263

def initialize(
  opening_tag:,
  keyword:,
  content:,
  closing_tag:,
  new_line:,
  location:
)
  super(new_line: new_line, location: location)
  @opening_tag = opening_tag
  # prune whitespace from keyword
  @keyword =
    if keyword
      Token.new(
        type: keyword.type,
        value: keyword.value.strip,
        location: keyword.location
      )
    end

  @content = content
  @content = prepare_content(content)
  @closing_tag = closing_tag
end

Instance Attribute Details

#closing_tagObject (readonly)

Returns the value of attribute closing_tag.



261
262
263
# File 'lib/syntax_tree/erb/nodes.rb', line 261

def closing_tag
  @closing_tag
end

#contentObject (readonly)

Returns the value of attribute content.



261
262
263
# File 'lib/syntax_tree/erb/nodes.rb', line 261

def content
  @content
end

#keywordObject (readonly)

Returns the value of attribute keyword.



261
262
263
# File 'lib/syntax_tree/erb/nodes.rb', line 261

def keyword
  @keyword
end

#opening_tagObject (readonly)

Returns the value of attribute opening_tag.



261
262
263
# File 'lib/syntax_tree/erb/nodes.rb', line 261

def opening_tag
  @opening_tag
end

Instance Method Details

#accept(visitor) ⇒ Object



288
289
290
# File 'lib/syntax_tree/erb/nodes.rb', line 288

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

#child_nodesObject Also known as: deconstruct



292
293
294
# File 'lib/syntax_tree/erb/nodes.rb', line 292

def child_nodes
  [opening_tag, keyword, content, closing_tag].compact
end

#deconstruct_keys(keys) ⇒ Object



310
311
312
313
314
315
316
317
# File 'lib/syntax_tree/erb/nodes.rb', line 310

def deconstruct_keys(keys)
  super.merge(
    opening_tag: opening_tag,
    keyword: keyword,
    content: content,
    closing_tag: closing_tag
  )
end

#new_lineObject



296
297
298
# File 'lib/syntax_tree/erb/nodes.rb', line 296

def new_line
  closing_tag&.new_line
end

#without_new_lineObject



300
301
302
303
304
305
306
# File 'lib/syntax_tree/erb/nodes.rb', line 300

def without_new_line
  self.class.new(
    **deconstruct_keys([]).merge(
      closing_tag: closing_tag.without_new_line
    )
  )
end