Class: Antlers::IfNode
- Inherits:
-
BranchNode
- Object
- AntlerNode
- BranchNode
- Antlers::IfNode
- Defined in:
- lib/nodes/if_node.rb
Instance Attribute Summary
Attributes included from Props
Attributes inherited from BranchNode
Attributes inherited from AntlerNode
Instance Method Summary collapse
-
#initialize(name:, value:, props: [], children: []) ⇒ IfNode
constructor
A new instance of IfNode.
- #render(current_binding: nil, parent_binding: nil, slot_node: nil) ⇒ Object
Methods included from Variables
Methods included from Queries
user_defined_string?, wrapped_in?
Methods inherited from AntlerNode
Constructor Details
#initialize(name:, value:, props: [], children: []) ⇒ IfNode
Returns a new instance of IfNode.
12 13 14 15 16 |
# File 'lib/nodes/if_node.rb', line 12 def initialize(name:, value:, props: [], children: []) super(name:, props:, children:) @value = value end |
Instance Method Details
#render(current_binding: nil, parent_binding: nil, slot_node: nil) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/nodes/if_node.rb', line 18 def render(current_binding: nil, parent_binding: nil, slot_node: nil) output = ''.dup if evaluate(name: @value, current_binding:) @children.each do |child| # Antlers nodes respond to "render", whereas HTML is stored as a string and output as is. output += (child.respond_to?(:render) ? child.render(current_binding:, parent_binding:, slot_node:) : child) || '' end end output end |