Class: Antlers::FormNode
- Inherits:
-
BranchNode
- Object
- AntlerNode
- BranchNode
- Antlers::FormNode
- Defined in:
- lib/nodes/form_node.rb
Instance Attribute Summary
Attributes included from Props
Attributes inherited from BranchNode
Attributes inherited from AntlerNode
Instance Method Summary collapse
-
#initialize(name:, action: nil, method: 'POST', props: [], children: []) ⇒ FormNode
constructor
A new instance of FormNode.
- #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:, action: nil, method: 'POST', props: [], children: []) ⇒ FormNode
Returns a new instance of FormNode.
12 13 14 15 16 17 |
# File 'lib/nodes/form_node.rb', line 12 def initialize(name:, action: nil, method: 'POST', props: [], children: []) super(name:, props:, children:) @action = action @method = method end |
Instance Method Details
#render(current_binding: nil, parent_binding: nil, slot_node: nil) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/nodes/form_node.rb', line 19 def render(current_binding: nil, parent_binding: nil, slot_node: nil) output = "<form action='#{@action}' method='#{@method}'>" @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 output += '</form>' output end |