lib/yaks/mapper/form/config.rb in yaks-0.9.0 vs lib/yaks/mapper/form/config.rb in yaks-0.10.0
- old
+ new
@@ -1,49 +1,48 @@
module Yaks
class Mapper
class Form
class Config
- include Attributes.new(
+ include Attribs.new(
name: nil,
action: nil,
title: nil,
method: nil,
media_type: nil,
- fields: [],
+ fields: [].freeze,
if: nil
)
- def self.builder
- @builder ||= Builder.new(self) do
- def_set :action, :title, :method, :media_type
- def_add :field, create: Field::Builder, append_to: :fields
- def_add :fieldset, create: Fieldset, append_to: :fields
- HTML5Forms::INPUT_TYPES.each do |type|
- def_add(type,
- create: Field::Builder,
- append_to: :fields,
- defaults: { type: type })
- end
- def_add :dynamic, create: DynamicField, append_to: :fields
- def_forward :condition
+ Builder = Yaks::Builder.new(self) do
+ def_set :action, :title, :method, :media_type
+ def_add :field, create: Field::Builder, append_to: :fields
+ def_add :fieldset, create: Fieldset, append_to: :fields
+ HTML5Forms::INPUT_TYPES.each do |type|
+ def_add(type,
+ create: Field::Builder,
+ append_to: :fields,
+ defaults: {type: type})
end
+ def_add :legend, create: Legend, append_to: :fields
+ def_add :dynamic, create: DynamicField, append_to: :fields
+ def_forward :condition
end
# Builder expects a `create' method. Alias to constructor
def self.create(options)
new(options)
end
# Build up a configuration based on an initial set of
# attributes, and a configuration block
def self.build(options = {}, &block)
- builder.create(options, &block)
+ Builder.create(options, &block)
end
# Build up a configuration based on a config block. Provide an
# object to be supplied to the block
def self.build_with_object(object, &block)
- builder.build(new, object, &block)
+ Builder.build(new, object, &block)
end
def condition(prc = nil, &blk)
with(if: prc || blk)
end