Class: SyntaxTree::ERB::CharData
- Defined in:
- lib/syntax_tree/erb/nodes.rb
Overview
A CharData contains either plain text or whitespace within an element. It wraps a single token value.
Instance Attribute Summary collapse
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Attributes inherited from Element
Instance Method Summary collapse
- #accept(visitor) ⇒ Object
- #child_nodes ⇒ Object (also: #deconstruct)
- #deconstruct_keys(keys) ⇒ Object
-
#initialize(value:, new_line:, location:) ⇒ CharData
constructor
A new instance of CharData.
- #skip? ⇒ Boolean
-
#without_new_line ⇒ Object
Also remove trailing whitespace.
Methods inherited from Node
Constructor Details
#initialize(value:, new_line:, location:) ⇒ CharData
Returns a new instance of CharData.
633 634 635 636 |
# File 'lib/syntax_tree/erb/nodes.rb', line 633 def initialize(value:, new_line:, location:) super(new_line: new_line, location: location) @value = value end |
Instance Attribute Details
#value ⇒ Object (readonly)
Returns the value of attribute value.
631 632 633 |
# File 'lib/syntax_tree/erb/nodes.rb', line 631 def value @value end |
Instance Method Details
#accept(visitor) ⇒ Object
638 639 640 |
# File 'lib/syntax_tree/erb/nodes.rb', line 638 def accept(visitor) visitor.visit_char_data(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
642 643 644 |
# File 'lib/syntax_tree/erb/nodes.rb', line 642 def child_nodes [value] end |
#deconstruct_keys(keys) ⇒ Object
648 649 650 |
# File 'lib/syntax_tree/erb/nodes.rb', line 648 def deconstruct_keys(keys) super.merge(value: value) end |
#skip? ⇒ Boolean
652 653 654 |
# File 'lib/syntax_tree/erb/nodes.rb', line 652 def skip? value.value.strip.empty? end |
#without_new_line ⇒ Object
Also remove trailing whitespace
657 658 659 660 661 662 663 664 665 666 667 668 669 |
# File 'lib/syntax_tree/erb/nodes.rb', line 657 def without_new_line self.class.new( **deconstruct_keys([]).merge( new_line: nil, value: Token.new( type: value.type, location: value.location, value: value.value.rstrip ) ) ) end |