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.

Parameters:

  • children (Array) (defaults to: [])

    any child nodes to initially assign to this node.



21
22
23
24
# File 'lib/cadenza/nodes/document_node.rb', line 21

def initialize(children=[])
  @children = children
  @blocks = {}
end

Instance Attribute Details

#blocksHash

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.

Returns:

  • (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



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

def blocks
  @blocks
end

#childrenArray

Returns any child nodes belonging to this one.

Returns:

  • (Array)

    any child nodes belonging to this one



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

def children
  @children
end

#extendsString

Returns the name of the template this document will inherit from.

Returns:

  • (String)

    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.

Parameters:

Returns:



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.

Parameters:



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.

Returns:

  • (Array)


44
45
46
# File 'lib/cadenza/nodes/document_node.rb', line 44

def implied_globals
  @children.map(&:implied_globals).flatten.uniq
end