Class: SyntaxTree::ERB::ErbContent

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Node

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

Constructor Details

#initialize(value:) ⇒ ErbContent

Returns a new instance of ErbContent.



462
463
464
465
466
467
468
# File 'lib/syntax_tree/erb/nodes.rb', line 462

def initialize(value:)
  if value.is_a?(Array)
    value =
      value.map { |token| token.is_a?(Token) ? token.value : token }.join
  end
  @value = SyntaxTree.parse(value.strip)
end

Instance Attribute Details

#valueObject (readonly)

Returns the value of attribute value.



460
461
462
# File 'lib/syntax_tree/erb/nodes.rb', line 460

def value
  @value
end

Instance Method Details

#accept(visitor) ⇒ Object



479
480
481
# File 'lib/syntax_tree/erb/nodes.rb', line 479

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

#blank?Boolean

Returns:

  • (Boolean)


470
471
472
473
474
475
476
477
# File 'lib/syntax_tree/erb/nodes.rb', line 470

def blank?
  value.nil? ||
    value
      .statements
      .child_nodes
      .reject { |node| node.is_a?(SyntaxTree::VoidStmt) }
      .empty?
end

#child_nodesObject Also known as: deconstruct



483
484
485
# File 'lib/syntax_tree/erb/nodes.rb', line 483

def child_nodes
  []
end

#deconstruct_keys(keys) ⇒ Object



489
490
491
# File 'lib/syntax_tree/erb/nodes.rb', line 489

def deconstruct_keys(keys)
  { value: value }
end