Class: SyntaxTree::ERB::ErbNode
- Defined in:
- lib/syntax_tree/erb/nodes.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#closing_tag ⇒ Object
readonly
Returns the value of attribute closing_tag.
-
#content ⇒ Object
readonly
Returns the value of attribute content.
-
#keyword ⇒ Object
readonly
Returns the value of attribute keyword.
-
#opening_tag ⇒ Object
readonly
Returns the value of attribute opening_tag.
Attributes inherited from Element
Instance Method Summary collapse
- #accept(visitor) ⇒ Object
- #child_nodes ⇒ Object (also: #deconstruct)
- #deconstruct_keys(keys) ⇒ Object
-
#initialize(opening_tag:, keyword:, content:, closing_tag:, new_line:, location:) ⇒ ErbNode
constructor
A new instance of ErbNode.
- #new_line ⇒ Object
- #without_new_line ⇒ Object
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_tag ⇒ Object (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 |
#content ⇒ Object (readonly)
Returns the value of attribute content.
276 277 278 |
# File 'lib/syntax_tree/erb/nodes.rb', line 276 def content @content end |
#keyword ⇒ Object (readonly)
Returns the value of attribute keyword.
276 277 278 |
# File 'lib/syntax_tree/erb/nodes.rb', line 276 def keyword @keyword end |
#opening_tag ⇒ Object (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_nodes ⇒ Object 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_line ⇒ Object
310 311 312 |
# File 'lib/syntax_tree/erb/nodes.rb', line 310 def new_line closing_tag&.new_line end |
#without_new_line ⇒ Object
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 |