Class: Formalist::Elements::CompoundField

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

Instance Attribute Summary

Attributes inherited from Formalist::Element

#attributes, #children, #errors, #input

Instance Method Summary collapse

Methods inherited from Formalist::Element

#type

Methods included from Formalist::Element::ClassInterface

attribute, attributes_schema, permitted_children, type

Constructor Details

#initialize(*args, attributes, children, input, errors) ⇒ CompoundField

Returns a new instance of CompoundField.



9
10
11
12
# File 'lib/formalist/elements/compound_field.rb', line 9

def initialize(*args, attributes, children, input, errors)
  super
  @children = children.map { |definition| definition.(input, errors) }
end

Instance Method Details

#to_astArray

Converts the compound field into an abstract syntax tree.

It takes the following format:

“‘

:compound_field, [params]

“‘

With the following parameters:

  1. Custom element type (or :compound_field otherwise)

  2. Form element attributes

  3. Child form elements

Examples:

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

Returns:

  • (Array)

    the compound field as an abstract syntax tree.

See Also:



40
41
42
43
44
45
46
# File 'lib/formalist/elements/compound_field.rb', line 40

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