Class: Antlers::IfNode
Constant Summary
collapse
- DEF_KEY =
:if_def
- END_KEY =
:if_end
Instance Attribute Summary
Attributes included from Props
#props
Attributes inherited from BranchNode
#children
Attributes inherited from AntlerNode
#name
Class Method Summary
collapse
Instance Method Summary
collapse
Methods included from Variables
#evaluate, #fallback
Methods included from Queries
user_defined_string?, wrapped_in?
Methods inherited from AntlerNode
#==, #end_name, #eql?, #hash
Constructor Details
#initialize(name:, value:, props: [], children: []) ⇒ IfNode
Returns a new instance of IfNode.
15
16
17
18
19
|
# File 'lib/nodes/if_node.rb', line 15
def initialize(name:, value:, props: [], children: [])
super(name:, props:, children:)
@value = value
end
|
Class Method Details
.build(segment:) ⇒ Object
38
39
40
|
# File 'lib/nodes/if_node.rb', line 38
def build(segment:, **)
new(name: segment[DEF_KEY], value: segment[DEF_KEY])
end
|
.match?(segment:) ⇒ Boolean
34
35
36
|
# File 'lib/nodes/if_node.rb', line 34
def match?(segment:)
segment[DEF_KEY]
end
|
Instance Method Details
#render(current_binding: nil, parent_binding: nil, slot_node: nil) ⇒ Object
21
22
23
24
25
26
27
28
29
30
31
|
# File 'lib/nodes/if_node.rb', line 21
def render(current_binding: nil, parent_binding: nil, slot_node: nil)
output = ''.dup
if evaluate(name: @value, current_binding:)
@children.each do |child|
output += child.render(current_binding:, parent_binding:, slot_node:) || ''
end
end
output
end
|