yaks 0.9.0 → 0.10.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +158 -56
- data/Rakefile +1 -3
- data/ataru_setup.rb +72 -0
- data/find_missing_tests.rb +34 -0
- data/lib/yaks.rb +8 -10
- data/lib/yaks/breaking_changes.rb +4 -6
- data/lib/yaks/builder.rb +1 -1
- data/lib/yaks/changelog.rb +1 -1
- data/lib/yaks/collection_mapper.rb +8 -5
- data/lib/yaks/collection_resource.rb +0 -1
- data/lib/yaks/config.rb +17 -7
- data/lib/yaks/configurable.rb +20 -14
- data/lib/yaks/default_policy.rb +82 -33
- data/lib/yaks/format.rb +7 -3
- data/lib/yaks/format/collection_json.rb +4 -4
- data/lib/yaks/format/hal.rb +1 -2
- data/lib/yaks/format/halo.rb +2 -4
- data/lib/yaks/format/json_api.rb +46 -27
- data/lib/yaks/html5_forms.rb +0 -2
- data/lib/yaks/mapper.rb +5 -5
- data/lib/yaks/mapper/association.rb +7 -7
- data/lib/yaks/mapper/association_mapper.rb +2 -0
- data/lib/yaks/mapper/attribute.rb +10 -4
- data/lib/yaks/mapper/config.rb +2 -2
- data/lib/yaks/mapper/form.rb +4 -10
- data/lib/yaks/mapper/form/config.rb +16 -17
- data/lib/yaks/mapper/form/dynamic_field.rb +1 -1
- data/lib/yaks/mapper/form/field.rb +16 -7
- data/lib/yaks/mapper/form/field/option.rb +5 -4
- data/lib/yaks/mapper/form/fieldset.rb +1 -1
- data/lib/yaks/mapper/form/legend.rb +18 -0
- data/lib/yaks/mapper/has_many.rb +1 -0
- data/lib/yaks/mapper/link.rb +7 -4
- data/lib/yaks/null_resource.rb +4 -5
- data/lib/yaks/pipeline.rb +2 -2
- data/lib/yaks/primitivize.rb +3 -2
- data/lib/yaks/reader/hal.rb +12 -13
- data/lib/yaks/reader/json_api.rb +50 -33
- data/lib/yaks/resource.rb +6 -7
- data/lib/yaks/resource/form.rb +2 -12
- data/lib/yaks/resource/form/field.rb +4 -3
- data/lib/yaks/resource/form/field/option.rb +1 -1
- data/lib/yaks/resource/form/fieldset.rb +1 -1
- data/lib/yaks/resource/form/legend.rb +18 -0
- data/lib/yaks/resource/has_fields.rb +13 -7
- data/lib/yaks/resource/link.rb +1 -1
- data/lib/yaks/runner.rb +5 -2
- data/lib/yaks/serializer.rb +2 -3
- data/lib/yaks/util.rb +7 -8
- data/lib/yaks/version.rb +1 -1
- data/spec/acceptance/acceptance_spec.rb +53 -38
- data/spec/acceptance/json_shared_examples.rb +45 -12
- data/spec/acceptance/models.rb +1 -1
- data/spec/integration/dynamic_form_fields_spec.rb +0 -1
- data/spec/integration/fieldset_spec.rb +18 -20
- data/spec/integration/map_to_resource_spec.rb +6 -6
- data/spec/json/{confucius.collection.json → confucius.collection_json.json} +0 -0
- data/spec/json/confucius.json_api.json +43 -27
- data/spec/json/list_of_quotes.collection_json.json +43 -0
- data/spec/json/list_of_quotes.hal.json +18 -0
- data/spec/json/list_of_quotes.json_api.json +25 -0
- data/spec/json/youtypeitwepostit.collection_json.json +45 -0
- data/spec/spec_helper.rb +4 -3
- data/spec/support/classes_for_policy_testing.rb +38 -14
- data/spec/support/deep_eql.rb +21 -18
- data/spec/support/pet_mapper.rb +2 -0
- data/spec/support/shared_contexts.rb +9 -9
- data/spec/unit/yaks/builder_spec.rb +41 -18
- data/spec/unit/yaks/collection_mapper_spec.rb +22 -19
- data/spec/unit/yaks/collection_resource_spec.rb +16 -8
- data/spec/unit/yaks/config_spec.rb +215 -19
- data/spec/unit/yaks/configurable_spec.rb +66 -7
- data/spec/unit/yaks/default_policy/derive_mapper_from_collection_spec.rb +47 -0
- data/spec/unit/yaks/default_policy/derive_mapper_from_item_spec.rb +114 -0
- data/spec/unit/yaks/default_policy/derive_mapper_from_object_spec.rb +29 -71
- data/spec/unit/yaks/default_policy_spec.rb +4 -5
- data/spec/unit/yaks/format/collection_json_spec.rb +35 -36
- data/spec/unit/yaks/format/hal_spec.rb +3 -3
- data/spec/unit/yaks/format/json_api_spec.rb +109 -68
- data/spec/unit/yaks/format_spec.rb +34 -0
- data/spec/unit/yaks/fp/callable_spec.rb +5 -3
- data/spec/unit/yaks/mapper/association_mapper_spec.rb +22 -4
- data/spec/unit/yaks/mapper/association_spec.rb +23 -11
- data/spec/unit/yaks/mapper/attribute_spec.rb +46 -7
- data/spec/unit/yaks/mapper/config_spec.rb +2 -3
- data/spec/unit/yaks/mapper/form/config_spec.rb +95 -0
- data/spec/unit/yaks/mapper/form/dynamic_field_spec.rb +30 -0
- data/spec/unit/yaks/mapper/form/field/option_spec.rb +48 -4
- data/spec/unit/yaks/mapper/form/field_spec.rb +43 -2
- data/spec/unit/yaks/mapper/form/fieldset_spec.rb +67 -8
- data/spec/unit/yaks/mapper/form/legend_spec.rb +52 -0
- data/spec/unit/yaks/mapper/form_spec.rb +84 -23
- data/spec/unit/yaks/mapper/has_many_spec.rb +39 -36
- data/spec/unit/yaks/mapper/has_one_spec.rb +28 -20
- data/spec/unit/yaks/mapper/link_spec.rb +68 -16
- data/spec/unit/yaks/mapper_spec.rb +118 -30
- data/spec/unit/yaks/null_resource_spec.rb +83 -52
- data/spec/unit/yaks/pipeline_spec.rb +101 -74
- data/spec/unit/yaks/primitivize_spec.rb +25 -6
- data/spec/unit/yaks/resource/form/field_spec.rb +5 -5
- data/spec/unit/yaks/resource/form/fieldset_spec.rb +7 -0
- data/spec/unit/yaks/resource/form/legend_spec.rb +8 -0
- data/spec/unit/yaks/resource/form_spec.rb +17 -37
- data/spec/unit/yaks/resource/has_fields_spec.rb +44 -3
- data/spec/unit/yaks/resource/link_spec.rb +11 -6
- data/spec/unit/yaks/resource_spec.rb +87 -98
- data/spec/unit/yaks/runner_spec.rb +112 -28
- data/spec/unit/yaks/serializer_spec.rb +1 -1
- data/spec/unit/yaks/util_spec.rb +30 -10
- data/spec/yaml/list_of_quotes.yaml +13 -0
- data/yaks.gemspec +21 -13
- metadata +129 -41
- data/lib/yaks/attributes.rb +0 -86
- data/lib/yaks/fp.rb +0 -26
- data/lib/yaks/identifier/link_relation.rb +0 -17
- data/resources/iana-link-relations.csv +0 -152
- data/spec/json/youtypeitwepostit.collection.json +0 -45
- data/spec/unit/yaks/attributes_spec.rb +0 -178
- data/spec/unit/yaks/fp_spec.rb +0 -29
data/lib/yaks/format.rb
CHANGED
@@ -26,7 +26,11 @@ module Yaks
|
|
26
26
|
@env = env
|
27
27
|
serialize_resource(resource)
|
28
28
|
end
|
29
|
-
|
29
|
+
alias_method :serialize, :call
|
30
|
+
|
31
|
+
# @abstract
|
32
|
+
def serialize_resource(_resource)
|
33
|
+
end
|
30
34
|
|
31
35
|
class << self
|
32
36
|
extend Util::Deprecated
|
@@ -76,8 +80,8 @@ module Yaks
|
|
76
80
|
end
|
77
81
|
|
78
82
|
def media_types
|
79
|
-
Format.all.each_with_object({}) do
|
80
|
-
|
83
|
+
Format.all.each_with_object({}) do |format, memo|
|
84
|
+
memo[format.format_name] = format.media_type
|
81
85
|
end
|
82
86
|
end
|
83
87
|
deprecated_alias :mime_types, :media_types
|
@@ -29,7 +29,7 @@ module Yaks
|
|
29
29
|
value: value
|
30
30
|
}
|
31
31
|
end
|
32
|
-
result = {
|
32
|
+
result = {data: attrs}
|
33
33
|
result[:href] = item.self_link.uri if item.self_link
|
34
34
|
item.links.each do |link|
|
35
35
|
next if link.rel.equal? :self
|
@@ -43,7 +43,7 @@ module Yaks
|
|
43
43
|
|
44
44
|
def serialize_links(resource)
|
45
45
|
resource.links.each_with_object([]) do |link, result|
|
46
|
-
result << {
|
46
|
+
result << {href: link.uri, rel: link.rel}
|
47
47
|
end
|
48
48
|
end
|
49
49
|
|
@@ -51,12 +51,12 @@ module Yaks
|
|
51
51
|
resource.forms.each_with_object([]) do |form, result|
|
52
52
|
next unless form_is_query? form
|
53
53
|
|
54
|
-
result << {
|
54
|
+
result << {rel: form.name, href: form.action}
|
55
55
|
result.last[:prompt] = form.title if form.title
|
56
56
|
|
57
57
|
form.fields_flat.each do |field|
|
58
58
|
result.last[:data] = [] unless result.last.key? :data
|
59
|
-
result.last[:data] << {
|
59
|
+
result.last[:data] << {name: field.name, value: nil.to_s}
|
60
60
|
result.last[:data].last[:prompt] = field.label if field.label
|
61
61
|
end
|
62
62
|
end
|
data/lib/yaks/format/hal.rb
CHANGED
@@ -87,7 +87,7 @@ module Yaks
|
|
87
87
|
def serialize_embedded(subresources)
|
88
88
|
subresources.each_with_object({}) do |sub, memo|
|
89
89
|
memo[sub.rels.first] = if sub.collection?
|
90
|
-
sub.map(
|
90
|
+
sub.map(&method(:serialize_resource))
|
91
91
|
elsif sub.null_resource?
|
92
92
|
nil
|
93
93
|
else
|
@@ -95,7 +95,6 @@ module Yaks
|
|
95
95
|
end
|
96
96
|
end
|
97
97
|
end
|
98
|
-
|
99
98
|
end
|
100
99
|
end
|
101
100
|
end
|
data/lib/yaks/format/halo.rb
CHANGED
@@ -33,11 +33,9 @@ module Yaks
|
|
33
33
|
fields: field.fields.map(&method(:serialize_form_field))
|
34
34
|
}
|
35
35
|
else
|
36
|
-
field.to_h_compact.each_with_object({}) do |(attr,value), hsh|
|
36
|
+
field.to_h_compact.each_with_object({}) do |(attr, value), hsh|
|
37
37
|
if attr == :options # <option>s of a <select>
|
38
|
-
|
39
|
-
hsh[:options] = value.map(&:to_h_compact)
|
40
|
-
end
|
38
|
+
hsh[:options] = value.map(&:to_h_compact) unless value.empty?
|
41
39
|
else
|
42
40
|
hsh[attr] = value
|
43
41
|
end
|
data/lib/yaks/format/json_api.rb
CHANGED
@@ -8,76 +8,95 @@ module Yaks
|
|
8
8
|
# @param [Yaks::Resource] resource
|
9
9
|
# @return [Hash]
|
10
10
|
def call(resource, _env = nil)
|
11
|
-
|
11
|
+
output = {}
|
12
|
+
if resource.collection?
|
13
|
+
output[:data] = resource.map(&method(:serialize_resource))
|
14
|
+
output[:links] = serialize_links(resource.links) if resource.links.any?
|
15
|
+
else
|
16
|
+
output[:data] = serialize_resource(resource)
|
17
|
+
end
|
18
|
+
included = resource.seq.each_with_object([]) do |res, array|
|
19
|
+
serialize_included_subresources(res.subresources, array)
|
20
|
+
end
|
21
|
+
output[:included] = included if included.any?
|
22
|
+
output[:meta] = resource[:meta] if resource[:meta]
|
23
|
+
|
24
|
+
output
|
25
|
+
end
|
12
26
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
27
|
+
# @param [Yaks::Resource] resource
|
28
|
+
# @return [Hash]
|
29
|
+
def serialize_links(links)
|
30
|
+
links.each_with_object({}) do |link, hash|
|
31
|
+
hash[link.rel] = link.uri
|
18
32
|
end
|
19
33
|
end
|
20
34
|
|
21
35
|
# @param [Yaks::Resource] resource
|
22
36
|
# @return [Hash]
|
23
37
|
def serialize_resource(resource)
|
24
|
-
result = {
|
38
|
+
result = {}
|
39
|
+
result[:type] = pluralize(resource.type)
|
40
|
+
result[:id] = resource[:id].to_s if resource[:id]
|
25
41
|
|
26
|
-
|
27
|
-
result[:
|
42
|
+
attributes = resource.attributes.reject { |k| k.equal?(:id) }
|
43
|
+
result[:attributes] = attributes if attributes.any?
|
28
44
|
|
29
|
-
|
30
|
-
|
31
|
-
|
45
|
+
result[:links] = {}
|
46
|
+
result[:links].update(serialize_subresource_links(resource.subresources))
|
47
|
+
result[:links].update(serialize_links(resource.links))
|
48
|
+
result.delete(:links) if result[:links].empty?
|
32
49
|
|
33
50
|
result
|
34
51
|
end
|
35
52
|
|
36
53
|
# @param [Yaks::Resource] subresource
|
37
54
|
# @return [Hash]
|
38
|
-
def
|
55
|
+
def serialize_subresource_links(subresources)
|
39
56
|
subresources.each_with_object({}) do |resource, hsh|
|
40
57
|
next if resource.null_resource?
|
41
|
-
hsh[resource.
|
58
|
+
hsh[resource.rels.first.sub(/^rel:/, '')] = serialize_subresource_link(resource)
|
42
59
|
end
|
43
60
|
end
|
44
61
|
|
45
62
|
# @param [Yaks::Resource] resource
|
46
63
|
# @return [Array, String]
|
47
|
-
def
|
64
|
+
def serialize_subresource_link(resource)
|
48
65
|
if resource.collection?
|
49
|
-
{
|
66
|
+
{linkage: resource.map{|r| {type: pluralize(r.type), id: r[:id].to_s} }}
|
50
67
|
else
|
51
|
-
{type: pluralize(resource.type), id: resource[:id]}
|
68
|
+
{linkage: {type: pluralize(resource.type), id: resource[:id].to_s}}
|
52
69
|
end
|
53
70
|
end
|
54
71
|
|
55
72
|
# @param [Hash] subresources
|
56
73
|
# @param [Array] array
|
57
74
|
# @return [Array]
|
58
|
-
def
|
75
|
+
def serialize_included_subresources(subresources, array)
|
59
76
|
subresources.each do |resources|
|
60
|
-
|
77
|
+
serialize_included_resources(resources, array)
|
61
78
|
end
|
62
79
|
end
|
63
80
|
|
64
81
|
# @param [Array] resources
|
65
|
-
# @param [Array]
|
82
|
+
# @param [Array] included
|
66
83
|
# @return [Array]
|
67
|
-
def
|
68
|
-
subresource.seq.each_with_object(
|
84
|
+
def serialize_included_resources(subresource, included)
|
85
|
+
subresource.seq.each_with_object(included) do |resource, memo|
|
69
86
|
serialize_subresource(resource, memo)
|
70
87
|
end
|
71
88
|
end
|
72
89
|
|
73
|
-
# {shows => [{id: 3, name: 'foo'}]}
|
90
|
+
# {shows => [{id: '3', name: 'foo'}]}
|
74
91
|
#
|
75
92
|
# @param [Yaks::Resource] resource
|
76
|
-
# @param [Hash]
|
93
|
+
# @param [Hash] included
|
77
94
|
# @return [Hash]
|
78
|
-
def serialize_subresource(resource,
|
79
|
-
|
80
|
-
|
95
|
+
def serialize_subresource(resource, included)
|
96
|
+
included << serialize_resource(resource) unless included.any? do |item|
|
97
|
+
item[:id].eql?(resource[:id].to_s) && item[:type].eql?(pluralize(resource.type))
|
98
|
+
end
|
99
|
+
serialize_included_subresources(resource.subresources, included)
|
81
100
|
end
|
82
101
|
|
83
102
|
def inverse
|
data/lib/yaks/html5_forms.rb
CHANGED
data/lib/yaks/mapper.rb
CHANGED
@@ -4,7 +4,7 @@ module Yaks
|
|
4
4
|
|
5
5
|
def_set :type
|
6
6
|
|
7
|
-
def_forward :
|
7
|
+
def_forward attributes: :add_attributes
|
8
8
|
def_forward :append_to
|
9
9
|
|
10
10
|
def_add :link, create: Link, append_to: :links
|
@@ -45,7 +45,7 @@ module Yaks
|
|
45
45
|
self.class.mapper_name(policy)
|
46
46
|
end
|
47
47
|
|
48
|
-
def call(object,
|
48
|
+
def call(object, _env = nil)
|
49
49
|
@object = object
|
50
50
|
|
51
51
|
return NullResource.new if object.nil?
|
@@ -55,20 +55,20 @@ module Yaks
|
|
55
55
|
:map_subresources,
|
56
56
|
:map_forms
|
57
57
|
].inject(Resource.new(type: mapper_name)) do |resource, method|
|
58
|
-
|
58
|
+
__send__(method, resource)
|
59
59
|
end
|
60
60
|
end
|
61
61
|
|
62
62
|
def load_attribute(name)
|
63
63
|
respond_to?(name) ? public_send(name) : object.public_send(name)
|
64
64
|
end
|
65
|
-
|
65
|
+
alias_method :load_association, :load_attribute
|
66
66
|
|
67
67
|
def expand_value(value)
|
68
68
|
Resolve(value, self)
|
69
69
|
end
|
70
70
|
|
71
|
-
def expand_uri(uri, expand)
|
71
|
+
def expand_uri(uri, expand = true)
|
72
72
|
return if uri.nil?
|
73
73
|
return Resolve(uri, self) if uri.respond_to?(:to_proc)
|
74
74
|
|
@@ -1,7 +1,7 @@
|
|
1
1
|
module Yaks
|
2
2
|
class Mapper
|
3
3
|
class Association
|
4
|
-
include
|
4
|
+
include Attribs.new(
|
5
5
|
name: Undefined,
|
6
6
|
item_mapper: Undefined,
|
7
7
|
rel: Undefined,
|
@@ -9,7 +9,8 @@ module Yaks
|
|
9
9
|
link_if: Undefined,
|
10
10
|
if: Undefined
|
11
11
|
),
|
12
|
-
Util
|
12
|
+
Util,
|
13
|
+
AbstractType
|
13
14
|
|
14
15
|
def self.create(name, options = {})
|
15
16
|
if options.key?(:mapper)
|
@@ -22,7 +23,7 @@ module Yaks
|
|
22
23
|
end
|
23
24
|
|
24
25
|
def add_to_resource(resource, parent_mapper, context)
|
25
|
-
return resource
|
26
|
+
return resource unless parent_mapper.expand_value(self.if)
|
26
27
|
AssociationMapper.new(parent_mapper, self, context).call(resource)
|
27
28
|
end
|
28
29
|
|
@@ -35,16 +36,15 @@ module Yaks
|
|
35
36
|
policy.derive_rel_from_association(self)
|
36
37
|
end
|
37
38
|
|
38
|
-
# @
|
39
|
-
|
40
|
-
|
39
|
+
# @param object
|
40
|
+
# @param context
|
41
|
+
abstract_method :map_resource
|
41
42
|
|
42
43
|
# support for HasOne and HasMany
|
43
44
|
def resolve_association_mapper(policy)
|
44
45
|
return item_mapper unless item_mapper.equal?(Undefined)
|
45
46
|
policy.derive_mapper_from_association(self)
|
46
47
|
end
|
47
|
-
|
48
48
|
end
|
49
49
|
end
|
50
50
|
end
|
@@ -1,14 +1,20 @@
|
|
1
1
|
module Yaks
|
2
2
|
class Mapper
|
3
3
|
class Attribute
|
4
|
-
include
|
4
|
+
include Attribs.new(:name, :block)
|
5
|
+
include Util
|
5
6
|
|
6
|
-
def
|
7
|
-
|
7
|
+
def self.create(name, _options = nil, &block)
|
8
|
+
new(name: name, block: block)
|
8
9
|
end
|
9
10
|
|
10
11
|
def add_to_resource(resource, mapper, _context)
|
11
|
-
|
12
|
+
if block
|
13
|
+
attribute = Resolve(block, mapper)
|
14
|
+
else
|
15
|
+
attribute = mapper.load_attribute(name)
|
16
|
+
end
|
17
|
+
resource.merge_attributes(name => attribute)
|
12
18
|
end
|
13
19
|
end
|
14
20
|
end
|
data/lib/yaks/mapper/config.rb
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
module Yaks
|
2
2
|
class Mapper
|
3
3
|
class Config
|
4
|
-
include
|
4
|
+
include Attribs.new(
|
5
5
|
type: nil, attributes: [], links: [], associations: [], forms: []
|
6
6
|
)
|
7
7
|
|
8
8
|
def add_attributes(*attrs)
|
9
|
-
append_to(:attributes, *attrs.map(&Attribute.method(:
|
9
|
+
append_to(:attributes, *attrs.map(&Attribute.method(:create)))
|
10
10
|
end
|
11
11
|
end
|
12
12
|
end
|
data/lib/yaks/mapper/form.rb
CHANGED
@@ -3,24 +3,19 @@ module Yaks
|
|
3
3
|
class Form
|
4
4
|
extend Forwardable, Util
|
5
5
|
|
6
|
-
|
7
6
|
def_delegators :config, :name, :action, :title, :method,
|
8
7
|
:media_type, :fields, :dynamic_blocks
|
9
8
|
|
10
9
|
def self.create(*args, &block)
|
11
10
|
args, options = extract_options(args)
|
12
|
-
|
13
|
-
if args.first.is_a? Symbol
|
14
|
-
options[:name] = args.first
|
15
|
-
end
|
16
|
-
|
11
|
+
options[:name] = args.first if args.first
|
17
12
|
new(config: Config.build(options, &block))
|
18
13
|
end
|
19
14
|
|
20
15
|
############################################################
|
21
16
|
# instance
|
22
17
|
|
23
|
-
include
|
18
|
+
include Attribs.new(:config)
|
24
19
|
|
25
20
|
def add_to_resource(resource, mapper, _context)
|
26
21
|
return resource if config.if && !mapper.expand_value(config.if)
|
@@ -30,16 +25,15 @@ module Yaks
|
|
30
25
|
def to_resource_form(mapper)
|
31
26
|
attrs = {
|
32
27
|
fields: config.to_resource_fields(mapper),
|
33
|
-
action: mapper.expand_uri(
|
28
|
+
action: mapper.expand_uri(action)
|
34
29
|
}
|
35
30
|
|
36
31
|
[:name, :title, :method, :media_type].each do |attr|
|
37
|
-
attrs[attr] = mapper.expand_value(
|
32
|
+
attrs[attr] = mapper.expand_value(public_send(attr))
|
38
33
|
end
|
39
34
|
|
40
35
|
Resource::Form.new(attrs)
|
41
36
|
end
|
42
|
-
|
43
37
|
end
|
44
38
|
end
|
45
39
|
end
|
@@ -2,30 +2,29 @@ module Yaks
|
|
2
2
|
class Mapper
|
3
3
|
class Form
|
4
4
|
class Config
|
5
|
-
include
|
5
|
+
include Attribs.new(
|
6
6
|
name: nil,
|
7
7
|
action: nil,
|
8
8
|
title: nil,
|
9
9
|
method: nil,
|
10
10
|
media_type: nil,
|
11
|
-
fields: [],
|
11
|
+
fields: [].freeze,
|
12
12
|
if: nil
|
13
13
|
)
|
14
14
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
defaults: { type: type })
|
25
|
-
end
|
26
|
-
def_add :dynamic, create: DynamicField, append_to: :fields
|
27
|
-
def_forward :condition
|
15
|
+
Builder = Yaks::Builder.new(self) do
|
16
|
+
def_set :action, :title, :method, :media_type
|
17
|
+
def_add :field, create: Field::Builder, append_to: :fields
|
18
|
+
def_add :fieldset, create: Fieldset, append_to: :fields
|
19
|
+
HTML5Forms::INPUT_TYPES.each do |type|
|
20
|
+
def_add(type,
|
21
|
+
create: Field::Builder,
|
22
|
+
append_to: :fields,
|
23
|
+
defaults: {type: type})
|
28
24
|
end
|
25
|
+
def_add :legend, create: Legend, append_to: :fields
|
26
|
+
def_add :dynamic, create: DynamicField, append_to: :fields
|
27
|
+
def_forward :condition
|
29
28
|
end
|
30
29
|
|
31
30
|
# Builder expects a `create' method. Alias to constructor
|
@@ -36,13 +35,13 @@ module Yaks
|
|
36
35
|
# Build up a configuration based on an initial set of
|
37
36
|
# attributes, and a configuration block
|
38
37
|
def self.build(options = {}, &block)
|
39
|
-
|
38
|
+
Builder.create(options, &block)
|
40
39
|
end
|
41
40
|
|
42
41
|
# Build up a configuration based on a config block. Provide an
|
43
42
|
# object to be supplied to the block
|
44
43
|
def self.build_with_object(object, &block)
|
45
|
-
|
44
|
+
Builder.build(new, object, &block)
|
46
45
|
end
|
47
46
|
|
48
47
|
def condition(prc = nil, &blk)
|