Class: Formalist::Elements::Section

Inherits:
Formalist::Element show all
Defined in:
lib/formalist/elements/section.rb

Instance Attribute Summary

Attributes inherited from Formalist::Element

#attributes, #children, #errors, #input, #name

Instance Method Summary collapse

Methods inherited from Formalist::Element

#==, build, fill, #initialize, #type

Methods included from Formalist::Element::ClassInterface

#attribute, #attributes_schema, #type

Constructor Details

This class inherits a constructor from Formalist::Element

Instance Method Details

#fill(input: {}, errors: {}) ⇒ Object



8
9
10
11
12
13
14
# File 'lib/formalist/elements/section.rb', line 8

def fill(input: {}, errors: {})
  super(
    input: input,
    errors: errors,
    children: children.map { |child| child.fill(input: input, errors: errors) },
  )
end

#to_astArray

Converts the section into an abstract syntax tree.

It takes the following format:

[:section, [params]]

With the following parameters:

  1. Section name
  2. Custom form element type (or :section otherwise)
  3. Form element attributes
  4. Child form elements

Examples:

"content" section

section.to_ast
# => [:section, [
  :content,
  :section,
  [:object, []],
  [...child elements...]
]]

Returns:

  • (Array)

    the section as an abstract syntax tree.

See Also:



43
44
45
46
47
48
49
50
# File 'lib/formalist/elements/section.rb', line 43

def to_ast
  [:section, [
    name,
    type,
    Element::Attributes.new(attributes).to_ast,
    children.map(&:to_ast),
  ]]
end