Class: Antlers::FormNode
Constant Summary
collapse
- DEF_KEY =
:form_def
- END_KEY =
:form_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:, action: nil, method: 'POST', props: [], children: []) ⇒ FormNode
Returns a new instance of FormNode.
15
16
17
18
19
20
|
# File 'lib/nodes/form_node.rb', line 15
def initialize(name:, action: nil, method: 'POST', props: [], children: [])
super(name:, props:, children:)
@action = action
@method = method
end
|
Class Method Details
.build(segment:) ⇒ Object
38
39
40
41
42
43
|
# File 'lib/nodes/form_node.rb', line 38
def build(segment:, **)
action, method = segment.values_at(DEF_KEY, :method)
return new(name: action, action:, method:) if method
new(name: action, action:)
end
|
.match?(segment:) ⇒ Boolean
34
35
36
|
# File 'lib/nodes/form_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
22
23
24
25
26
27
28
29
30
31
|
# File 'lib/nodes/form_node.rb', line 22
def render(current_binding: nil, parent_binding: nil, slot_node: nil)
output = "<form action='#{@action}' method='#{@method}'>"
@children.each do |child|
output += child.render(current_binding:, parent_binding:, slot_node:) || ''
end
output += '</form>'
output
end
|