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.



278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
# File 'lib/syntax_tree/erb/nodes.rb', line 278

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 = prepare_content(content)
  @closing_tag = closing_tag
end

Instance Attribute Details

#closing_tagObject (readonly)

Returns the value of attribute closing_tag.



276
277
278
# File 'lib/syntax_tree/erb/nodes.rb', line 276

def closing_tag
  @closing_tag
end

#contentObject (readonly)

Returns the value of attribute content.



276
277
278
# File 'lib/syntax_tree/erb/nodes.rb', line 276

def content
  @content
end

#keywordObject (readonly)

Returns the value of attribute keyword.



276
277
278
# File 'lib/syntax_tree/erb/nodes.rb', line 276

def keyword
  @keyword
end

#opening_tagObject (readonly)

Returns the value of attribute opening_tag.



276
277
278
# File 'lib/syntax_tree/erb/nodes.rb', line 276

def opening_tag
  @opening_tag
end

Instance Method Details

#accept(visitor) ⇒ Object



302
303
304
# File 'lib/syntax_tree/erb/nodes.rb', line 302

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

#child_nodesObject Also known as: deconstruct



306
307
308
# File 'lib/syntax_tree/erb/nodes.rb', line 306

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

#deconstruct_keys(keys) ⇒ Object



324
325
326
327
328
329
330
331
# File 'lib/syntax_tree/erb/nodes.rb', line 324

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

#new_lineObject



310
311
312
# File 'lib/syntax_tree/erb/nodes.rb', line 310

def new_line
  closing_tag&.new_line
end

#without_new_lineObject



314
315
316
317
318
319
320
# File 'lib/syntax_tree/erb/nodes.rb', line 314

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