Class: Cadenza::DocumentNode

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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

#blocksHash



16
17
18
# File 'lib/cadenza/nodes/document_node.rb', line 16

def blocks
  @blocks
end

#childrenArray



11
12
13
# File 'lib/cadenza/nodes/document_node.rb', line 11

def children
  @children
end

#extendsString



8
9
10
# File 'lib/cadenza/nodes/document_node.rb', line 8

def extends
  @extends
end

Instance Method Details

#==(rhs) ⇒ Boolean



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_globalsArray

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