Class: Twig::Node::Base
- Inherits:
-
Object
show all
- Defined in:
- lib/twig/node/base.rb
Direct Known Subclasses
Block, BlockReference, Empty, Expression::Base, For, ForLoop, If, Include, Module, Nodes, Print, Text, Yield
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(nodes = {}, attributes = {}, lineno = 0) ⇒ Base
Returns a new instance of Base.
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
# File 'lib/twig/node/base.rb', line 20
def initialize(nodes = {}, attributes = {}, lineno = 0)
invalid = nodes.
values.
detect { |node| !node.class.ancestors.include?(Node::Base) }
raise "#{invalid.inspect} does not extend from #{Node::Base.name}" if invalid
@nodes = AutoHash[nodes]
@nodes.default_proc = ->(_hash, key) { raise "Node '#{key}' does not exist" }
@attributes = attributes
@attributes.default_proc = ->(_hash, key) { raise "Attribute '#{key}' does not exist" }
@lineno = lineno
@tag = nil
end
|
Instance Attribute Details
#attributes ⇒ Hash
9
10
11
|
# File 'lib/twig/node/base.rb', line 9
def attributes
@attributes
end
|
#lineno ⇒ Object
Returns the value of attribute lineno.
6
7
8
|
# File 'lib/twig/node/base.rb', line 6
def lineno
@lineno
end
|
15
16
17
|
# File 'lib/twig/node/base.rb', line 15
def nodes
@nodes
end
|
#source_context ⇒ Source
12
13
14
|
# File 'lib/twig/node/base.rb', line 12
def source_context
@source_context
end
|
#tag ⇒ Object
Returns the value of attribute tag.
6
7
8
|
# File 'lib/twig/node/base.rb', line 6
def tag
@tag
end
|
Instance Method Details
#compile(compiler) ⇒ Object
45
46
47
|
# File 'lib/twig/node/base.rb', line 45
def compile(compiler)
@nodes.each_value { |node| compiler.subcompile(node) }
end
|
#template_name ⇒ String
56
57
58
|
# File 'lib/twig/node/base.rb', line 56
def template_name
source_context.name
end
|