Class: Cadenza::DocumentNode
- Inherits:
-
Object
- Object
- Cadenza::DocumentNode
- Defined in:
- lib/cadenza/nodes/document_node.rb
Overview
The DocumentNode is intended to be the root node of any parsed AST in Cadenza. In addition to holding the primary children it also holds data that affects the entire document, such as block definitions and the name of any extended template.
Instance Attribute Summary collapse
-
#blocks ⇒ Hash
A mapping of any blocks defined in this document where the key is the name of the block and the value is the BlockNode itself.
-
#children ⇒ Array
Any child nodes belonging to this one.
-
#extends ⇒ String
The name of the template this document will inherit from.
Instance Method Summary collapse
-
#==(rhs) ⇒ Boolean
If the given DocumentNode is equivalent by value to this one.
-
#add_block(block) ⇒ Object
adds the given BlockNode to this document replacing any existing definition of the same name.
-
#implied_globals ⇒ Array
returns a list of any global variable names implied by examining the children of this node.
-
#initialize(children = []) ⇒ DocumentNode
constructor
creates a new DocumentNode with the optional children nodes attached to it.
Constructor Details
#initialize(children = []) ⇒ DocumentNode
creates a new Cadenza::DocumentNode with the optional children nodes attached to it.
21 22 23 24 |
# File 'lib/cadenza/nodes/document_node.rb', line 21 def initialize(children=[]) @children = children @blocks = {} end |
Instance Attribute Details
#blocks ⇒ Hash
Returns a mapping of any blocks defined in this document where the key is the name of the block and the value is the BlockNode itself.
16 17 18 |
# File 'lib/cadenza/nodes/document_node.rb', line 16 def blocks @blocks end |
#children ⇒ Array
Returns any child nodes belonging to this one.
11 12 13 |
# File 'lib/cadenza/nodes/document_node.rb', line 11 def children @children end |
#extends ⇒ String
Returns the name of the template this document will inherit from.
8 9 10 |
# File 'lib/cadenza/nodes/document_node.rb', line 8 def extends @extends end |
Instance Method Details
#==(rhs) ⇒ Boolean
Returns if the given Cadenza::DocumentNode is equivalent by value to this one.
28 29 30 31 32 |
# File 'lib/cadenza/nodes/document_node.rb', line 28 def ==(rhs) @children == rhs.children and @extends == rhs.extends and @blocks == rhs.blocks end |
#add_block(block) ⇒ Object
adds the given BlockNode to this document replacing any existing definition of the same name.
37 38 39 |
# File 'lib/cadenza/nodes/document_node.rb', line 37 def add_block(block) @blocks[block.name] = block end |
#implied_globals ⇒ Array
returns a list of any global variable names implied by examining the children of this node.
44 45 46 |
# File 'lib/cadenza/nodes/document_node.rb', line 44 def implied_globals @children.map(&:implied_globals).flatten.uniq end |