Class: Antlers::ForNode
- Inherits:
-
BranchNode
- Object
- AntlerNode
- BranchNode
- Antlers::ForNode
- Defined in:
- lib/nodes/for_node.rb
Instance Attribute Summary collapse
-
#children ⇒ Object
Returns the value of attribute children.
Attributes included from Props
Attributes inherited from AntlerNode
Instance Method Summary collapse
-
#initialize(name:, item:, items:, props: [], children: []) ⇒ ForNode
constructor
A new instance of ForNode.
- #render(current_binding: nil, parent_binding: nil, slot_node: nil, namespace: nil) ⇒ Object
Methods included from Variables
Methods inherited from AntlerNode
Constructor Details
#initialize(name:, item:, items:, props: [], children: []) ⇒ ForNode
Returns a new instance of ForNode.
14 15 16 17 18 19 |
# File 'lib/nodes/for_node.rb', line 14 def initialize(name:, item:, items:, props: [], children: []) super(name:, props:, children:) @item = item @items = items end |
Instance Attribute Details
#children ⇒ Object
Returns the value of attribute children.
12 13 14 |
# File 'lib/nodes/for_node.rb', line 12 def children @children end |
Instance Method Details
#render(current_binding: nil, parent_binding: nil, slot_node: nil, namespace: nil) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/nodes/for_node.rb', line 21 def render(current_binding: nil, parent_binding: nil, slot_node: nil, namespace: nil) output = '' evaluate_variable(name: @items, current_binding:).each do |item| current_binding.local_variable_set(@item, item) @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:, namespace:) : child) || '' end end output end |