Class: Antlers::FormNode

Inherits:
BranchNode show all
Includes:
Props, Variables
Defined in:
lib/nodes/form_node.rb

Instance Attribute Summary

Attributes included from Props

#props

Attributes inherited from BranchNode

#children

Attributes inherited from AntlerNode

#name

Instance Method Summary collapse

Methods included from Variables

#evaluate, #fallback

Methods included from Queries

user_defined_string?, wrapped_in?

Methods inherited from AntlerNode

#==, #eql?, #hash

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