formalist 0.2.2 → 0.2.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +7 -3
- data/Gemfile.lock +36 -38
- data/README.md +8 -4
- data/Rakefile +0 -7
- data/lib/formalist/element/attributes.rb +54 -0
- data/lib/formalist/element/class_interface.rb +133 -0
- data/lib/formalist/element/definition.rb +55 -0
- data/lib/formalist/element/permitted_children.rb +46 -0
- data/lib/formalist/element.rb +51 -0
- data/lib/formalist/elements/attr.rb +74 -0
- data/lib/formalist/elements/compound_field.rb +49 -0
- data/lib/formalist/elements/field.rb +73 -0
- data/lib/formalist/elements/group.rb +50 -0
- data/lib/formalist/elements/many.rb +125 -0
- data/lib/formalist/elements/section.rb +58 -0
- data/lib/formalist/elements/standard/check_box.rb +20 -0
- data/lib/formalist/elements/standard/date_field.rb +12 -0
- data/lib/formalist/elements/standard/date_time_field.rb +12 -0
- data/lib/formalist/elements/standard/hidden_field.rb +11 -0
- data/lib/formalist/elements/standard/multi_selection_field.rb +16 -0
- data/lib/formalist/elements/standard/number_field.rb +17 -0
- data/lib/formalist/elements/standard/radio_buttons.rb +13 -0
- data/lib/formalist/elements/standard/select_box.rb +13 -0
- data/lib/formalist/elements/standard/selection_field.rb +16 -0
- data/lib/formalist/elements/standard/text_area.rb +15 -0
- data/lib/formalist/elements/standard/text_field.rb +14 -0
- data/lib/formalist/elements/standard.rb +11 -0
- data/lib/formalist/elements.rb +20 -0
- data/lib/formalist/form/definition_context.rb +58 -4
- data/lib/formalist/form/result.rb +5 -27
- data/lib/formalist/form.rb +15 -35
- data/lib/formalist/types.rb +30 -0
- data/lib/formalist/version.rb +1 -1
- data/lib/formalist.rb +0 -20
- data/spec/examples.txt +8 -7
- data/spec/integration/dependency_injection_spec.rb +54 -0
- data/spec/integration/form_spec.rb +86 -13
- data/spec/spec_helper.rb +12 -5
- data/spec/support/constants.rb +11 -0
- data/spec/unit/elements/standard/check_box_spec.rb +33 -0
- metadata +36 -63
- data/lib/formalist/definition_compiler.rb +0 -61
- data/lib/formalist/display_adapters/default.rb +0 -9
- data/lib/formalist/display_adapters/radio.rb +0 -19
- data/lib/formalist/display_adapters/select.rb +0 -19
- data/lib/formalist/display_adapters/textarea.rb +0 -14
- data/lib/formalist/display_adapters.rb +0 -16
- data/lib/formalist/form/definition/attr.rb +0 -20
- data/lib/formalist/form/definition/component.rb +0 -31
- data/lib/formalist/form/definition/field.rb +0 -29
- data/lib/formalist/form/definition/group.rb +0 -31
- data/lib/formalist/form/definition/many.rb +0 -41
- data/lib/formalist/form/definition/section.rb +0 -23
- data/lib/formalist/form/definition.rb +0 -37
- data/lib/formalist/form/result/attr.rb +0 -82
- data/lib/formalist/form/result/component.rb +0 -51
- data/lib/formalist/form/result/field.rb +0 -77
- data/lib/formalist/form/result/group.rb +0 -51
- data/lib/formalist/form/result/many.rb +0 -123
- data/lib/formalist/form/result/section.rb +0 -54
- data/lib/formalist/form/validated_result.rb +0 -35
- data/lib/formalist/output_compiler.rb +0 -43
- data/lib/formalist/validation/collection_rules_compiler.rb +0 -77
- data/lib/formalist/validation/predicate_list_compiler.rb +0 -73
- data/lib/formalist/validation/value_rules_compiler.rb +0 -96
- data/spec/integration/display_adapters_spec.rb +0 -55
- data/spec/integration/validation_spec.rb +0 -86
- data/spec/unit/output_compiler_spec.rb +0 -70
data/lib/formalist/form.rb
CHANGED
@@ -1,52 +1,32 @@
|
|
1
|
-
require "json"
|
2
1
|
require "dry-configurable"
|
3
|
-
require "
|
4
|
-
require "
|
5
|
-
require "formalist/
|
6
|
-
require "formalist/output_compiler"
|
7
|
-
require "formalist/display_adapters"
|
8
|
-
require "formalist/form/definition"
|
2
|
+
require "formalist/elements"
|
3
|
+
require "formalist/form/definition_context"
|
4
|
+
require "formalist/element/permitted_children"
|
9
5
|
require "formalist/form/result"
|
10
6
|
|
11
7
|
module Formalist
|
12
8
|
class Form
|
13
9
|
extend Dry::Configurable
|
14
|
-
extend Definition
|
15
10
|
|
16
|
-
setting :
|
17
|
-
|
18
|
-
def self.display_adapters
|
19
|
-
config.display_adapters
|
20
|
-
end
|
11
|
+
setting :elements_container, Elements
|
21
12
|
|
22
13
|
# @api private
|
23
14
|
def self.elements
|
24
|
-
@
|
25
|
-
end
|
26
|
-
|
27
|
-
# @api private
|
28
|
-
attr_reader :schema
|
29
|
-
|
30
|
-
# @api private
|
31
|
-
attr_reader :elements
|
32
|
-
|
33
|
-
def initialize(schema)
|
34
|
-
definition_compiler = DefinitionCompiler.new(self.class.display_adapters)
|
35
|
-
|
36
|
-
@elements = definition_compiler.call(self.class.elements)
|
37
|
-
@schema = schema
|
15
|
+
@elements ||= []
|
38
16
|
end
|
39
17
|
|
40
|
-
|
41
|
-
|
18
|
+
# @api public
|
19
|
+
def self.define(&block)
|
20
|
+
@elements = DefinitionContext.new(
|
21
|
+
container: config.elements_container,
|
22
|
+
permissions: Element::PermittedChildren.all
|
23
|
+
).call(&block).elements
|
42
24
|
end
|
43
25
|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
input = form_schema.(form_data).output
|
49
|
-
build(input)
|
26
|
+
# @api public
|
27
|
+
def build(input = {}, messages = {})
|
28
|
+
elements = self.class.elements.map { |el| el.resolve(self) }
|
29
|
+
Result.new(input, messages, elements)
|
50
30
|
end
|
51
31
|
end
|
52
32
|
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require "dry-types"
|
2
|
+
require "dry-logic"
|
3
|
+
|
4
|
+
Dry::Types::Predicates.predicate :respond_to? do |method_name, value|
|
5
|
+
value.respond_to?(method_name)
|
6
|
+
end
|
7
|
+
|
8
|
+
module Formalist
|
9
|
+
module Types
|
10
|
+
include Dry::Types.module
|
11
|
+
|
12
|
+
ElementName = Types::Strict::Symbol.constrained(min_size: 1)
|
13
|
+
OptionsList = Types::Array.member(Formalist::Types::Array.member(Formalist::Types::Strict::String).constrained(size: 2)).constrained(min_size: 1)
|
14
|
+
|
15
|
+
# The SelectionField and MultiSelectionField require a _somewhat_ specific
|
16
|
+
# data structure:
|
17
|
+
#
|
18
|
+
# {id: 123, label: 'foo'}
|
19
|
+
#
|
20
|
+
# It’s expected that `id` is the relational representation of the object.
|
21
|
+
# And label could/should be optional if the form defines a custom
|
22
|
+
# `render_as` attribute
|
23
|
+
SelectionsList = Formalist::Types::Strict::Array.member(Formalist::Types::Strict::Hash)
|
24
|
+
|
25
|
+
Validation = Types::Strict::Hash
|
26
|
+
|
27
|
+
Dependency = Dry::Types::Definition[Object].new(Object)
|
28
|
+
Function = Dependency.constrained(respond_to: :call)
|
29
|
+
end
|
30
|
+
end
|
data/lib/formalist/version.rb
CHANGED
data/lib/formalist.rb
CHANGED
@@ -1,21 +1 @@
|
|
1
|
-
module Formalist
|
2
|
-
DEFAULT_DISPLAY_ADAPTER = "default".freeze
|
3
|
-
end
|
4
|
-
|
5
|
-
# Temporarily monkey-patch over a dry-validation bug (intput type compiler for
|
6
|
-
# form schemas not being passed the right set of rules).
|
7
|
-
require "dry-validation"
|
8
|
-
require "dry/validation/schema/form"
|
9
|
-
module Dry
|
10
|
-
module Validation
|
11
|
-
class Schema::Form < Schema
|
12
|
-
def initialize(rules = [])
|
13
|
-
super
|
14
|
-
# @input_type = InputTypeCompiler.new.(self.class.rules.map(&:to_ast))
|
15
|
-
@input_type = InputTypeCompiler.new.(self.class.rule_ast + rules.map(&:to_ast))
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
1
|
require "formalist/form"
|
data/spec/examples.txt
CHANGED
@@ -1,7 +1,8 @@
|
|
1
|
-
example_id
|
2
|
-
|
3
|
-
./spec/integration/
|
4
|
-
./spec/integration/
|
5
|
-
./spec/
|
6
|
-
./spec/
|
7
|
-
./spec/unit/
|
1
|
+
example_id | status | run_time |
|
2
|
+
-------------------------------------------------------- | ------ | --------------- |
|
3
|
+
./spec/integration/dependency_injection_spec.rb[1:1] | passed | 0.00111 seconds |
|
4
|
+
./spec/integration/form_spec.rb[1:1] | passed | 0.01078 seconds |
|
5
|
+
./spec/unit/elements/standard/check_box_spec.rb[1:1:1:1] | passed | 0.00026 seconds |
|
6
|
+
./spec/unit/elements/standard/check_box_spec.rb[1:1:2:1] | passed | 0.00023 seconds |
|
7
|
+
./spec/unit/elements/standard/check_box_spec.rb[1:1:3:1] | passed | 0.00019 seconds |
|
8
|
+
./spec/unit/elements/standard/check_box_spec.rb[1:1:4:1] | passed | 0.00107 seconds |
|
@@ -0,0 +1,54 @@
|
|
1
|
+
require "dry-auto_inject"
|
2
|
+
require "formalist/elements/standard"
|
3
|
+
|
4
|
+
RSpec.describe "Dependency injection" do
|
5
|
+
let(:schema) {
|
6
|
+
Dry::Validation.Schema do
|
7
|
+
key(:status).required
|
8
|
+
end
|
9
|
+
}
|
10
|
+
|
11
|
+
subject(:form) {
|
12
|
+
Class.new(Formalist::Form) do
|
13
|
+
include Test::HashImport["fetch_options"]
|
14
|
+
|
15
|
+
define do
|
16
|
+
select_box :status, options: dep(:status_options)
|
17
|
+
end
|
18
|
+
|
19
|
+
def status_options
|
20
|
+
fetch_options.map { |option| [option, option.capitalize] }
|
21
|
+
end
|
22
|
+
end.new
|
23
|
+
}
|
24
|
+
|
25
|
+
before do
|
26
|
+
Test::Container = Class.new do
|
27
|
+
extend Dry::Container::Mixin
|
28
|
+
end
|
29
|
+
|
30
|
+
Test::Container.register :fetch_options, -> { %w[draft published] }
|
31
|
+
|
32
|
+
auto_inject = Dry::AutoInject(Test::Container)
|
33
|
+
Test::HashImport = -> *keys do
|
34
|
+
auto_inject.hash[*keys]
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
it "supports dependency injection via the initializer's options hash" do
|
39
|
+
expect(form.build.to_ast).to eql [
|
40
|
+
[:field, [
|
41
|
+
:status,
|
42
|
+
:select_box,
|
43
|
+
nil,
|
44
|
+
[],
|
45
|
+
[:object, [
|
46
|
+
[:options, [:array, [
|
47
|
+
[:array, [[:value, ["draft"]], [:value, ["Draft"]]]],
|
48
|
+
[:array, [[:value, ["published"]], [:value, ["Published"]]]]
|
49
|
+
]]]
|
50
|
+
]]
|
51
|
+
]]
|
52
|
+
]
|
53
|
+
end
|
54
|
+
end
|
@@ -1,31 +1,104 @@
|
|
1
1
|
RSpec.describe Formalist::Form do
|
2
2
|
let(:schema) {
|
3
|
-
|
4
|
-
key(:title
|
5
|
-
key(:rating
|
6
|
-
|
3
|
+
Dry::Validation.Schema do
|
4
|
+
key(:title).required
|
5
|
+
key(:rating).required(:int?)
|
6
|
+
|
7
|
+
key(:reviews).each do
|
8
|
+
key(:summary).required
|
9
|
+
key(:rating).required(:int?, gteq?: 1, lteq?: 10)
|
10
|
+
end
|
11
|
+
|
12
|
+
key(:meta).schema do
|
13
|
+
key(:pages).required(:int?, gteq?: 1)
|
14
|
+
end
|
15
|
+
end
|
7
16
|
}
|
8
17
|
|
9
18
|
subject(:form) {
|
10
19
|
Class.new(Formalist::Form) do
|
11
|
-
|
12
|
-
|
13
|
-
|
20
|
+
define do
|
21
|
+
compound_field do
|
22
|
+
field :title, validate: {filled: true}
|
23
|
+
field :rating, validate: {filled: true}
|
24
|
+
end
|
25
|
+
|
26
|
+
many :reviews do
|
27
|
+
field :summary, validate: {filled: true}
|
28
|
+
field :rating, validate: {filled: true}
|
29
|
+
end
|
30
|
+
|
31
|
+
attr :meta do
|
32
|
+
field :pages, validate: {filled: true}
|
33
|
+
end
|
14
34
|
end
|
15
|
-
end.new
|
35
|
+
end.new
|
16
36
|
}
|
17
37
|
|
18
38
|
it "outputs an AST" do
|
19
|
-
|
39
|
+
input = {
|
40
|
+
title: "Aurora",
|
41
|
+
rating: "10",
|
42
|
+
reviews: [
|
43
|
+
{
|
44
|
+
summary: "",
|
45
|
+
rating: 10
|
46
|
+
},
|
47
|
+
{
|
48
|
+
summary: "Great!",
|
49
|
+
rating: 0
|
50
|
+
}
|
51
|
+
],
|
52
|
+
meta: {
|
53
|
+
pages: 0
|
54
|
+
}
|
55
|
+
}
|
56
|
+
|
57
|
+
result = schema.(input)
|
20
58
|
|
21
|
-
expect(form.build(
|
22
|
-
[:
|
59
|
+
expect(form.build(result.output, result.messages).to_ast).to eq [
|
60
|
+
[:compound_field, [
|
61
|
+
:compound_field,
|
62
|
+
[:object, []],
|
63
|
+
[
|
64
|
+
[:field, [:title, :field, "Aurora", [], [:object, []]]],
|
65
|
+
[:field, [:rating, :field, "10", ["must be an integer"], [:object, []]]]
|
66
|
+
]
|
67
|
+
]],
|
68
|
+
[:many, [
|
69
|
+
:reviews,
|
70
|
+
:many,
|
23
71
|
[],
|
72
|
+
[:object, [
|
73
|
+
[:allow_create, [:value, [true]]],
|
74
|
+
[:allow_update, [:value, [true]]],
|
75
|
+
[:allow_destroy, [:value, [true]]],
|
76
|
+
[:allow_reorder, [:value, [true]]]
|
77
|
+
]],
|
24
78
|
[
|
25
|
-
[:field, [:
|
26
|
-
[:field, [:rating,
|
79
|
+
[:field, [:summary, :field, nil, [], [:object, []]]],
|
80
|
+
[:field, [:rating, :field, nil, [], [:object, []]]]
|
27
81
|
],
|
82
|
+
[
|
83
|
+
[
|
84
|
+
[:field, [:summary, :field, "", ["must be filled"], [:object, []]]],
|
85
|
+
[:field, [:rating, :field, 10, [], [:object, []]]]
|
86
|
+
],
|
87
|
+
[
|
88
|
+
[:field, [:summary, :field, "Great!", [], [:object, []]]],
|
89
|
+
[:field, [:rating, :field, 0, ["must be greater than or equal to 1"], [:object, []]]]
|
90
|
+
]
|
91
|
+
]
|
28
92
|
]],
|
93
|
+
[:attr, [
|
94
|
+
:meta,
|
95
|
+
:attr,
|
96
|
+
[],
|
97
|
+
[:object, []],
|
98
|
+
[
|
99
|
+
[:field, [:pages, :field, 0, ["must be greater than or equal to 1"], [:object, []]]]
|
100
|
+
]
|
101
|
+
]]
|
29
102
|
]
|
30
103
|
end
|
31
104
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,12 +1,19 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
1
|
+
if RUBY_ENGINE == "ruby"
|
2
|
+
require "codeclimate-test-reporter"
|
3
|
+
CodeClimate::TestReporter.start
|
4
|
+
|
5
|
+
require "simplecov"
|
6
|
+
SimpleCov.start do
|
7
|
+
add_filter "/spec/"
|
8
|
+
end
|
5
9
|
end
|
6
10
|
|
7
|
-
|
11
|
+
begin
|
12
|
+
require "byebug"
|
13
|
+
rescue LoadError; end
|
8
14
|
|
9
15
|
require "formalist"
|
16
|
+
require "dry-validation"
|
10
17
|
|
11
18
|
# Requires supporting ruby files with custom matchers and macros, etc, in
|
12
19
|
# spec/support/ and its subdirectories. Files matching `spec/**/*_spec.rb` are
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
require "formalist/elements/standard/check_box"
|
3
|
+
|
4
|
+
RSpec.describe Formalist::Elements::CheckBox do
|
5
|
+
subject(:check_box) {
|
6
|
+
Formalist::Elements::CheckBox.new(:published, attributes, [], {published: input}, errors)
|
7
|
+
}
|
8
|
+
|
9
|
+
let(:attributes) { {} }
|
10
|
+
let(:input) { nil }
|
11
|
+
let(:errors) { {} }
|
12
|
+
|
13
|
+
describe "input" do
|
14
|
+
context "is nil" do
|
15
|
+
specify { expect(check_box.input).to eql false }
|
16
|
+
end
|
17
|
+
|
18
|
+
context "is false" do
|
19
|
+
let(:input) { false }
|
20
|
+
specify { expect(check_box.input).to eql false }
|
21
|
+
end
|
22
|
+
|
23
|
+
context "is true" do
|
24
|
+
let(:input) { true }
|
25
|
+
specify { expect(check_box.input).to eql true }
|
26
|
+
end
|
27
|
+
|
28
|
+
context "is any other value" do
|
29
|
+
let(:input) { "something" }
|
30
|
+
specify { expect(check_box.input).to eql true }
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: formalist
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tim Riley
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-04-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: dry-configurable
|
@@ -39,19 +39,19 @@ dependencies:
|
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
|
-
name: dry-
|
42
|
+
name: dry-types
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- - "
|
45
|
+
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: 0
|
47
|
+
version: '0'
|
48
48
|
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- - "
|
52
|
+
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: 0
|
54
|
+
version: '0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: inflecto
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -80,20 +80,6 @@ dependencies:
|
|
80
80
|
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '1.10'
|
83
|
-
- !ruby/object:Gem::Dependency
|
84
|
-
name: byebug
|
85
|
-
requirement: !ruby/object:Gem::Requirement
|
86
|
-
requirements:
|
87
|
-
- - ">="
|
88
|
-
- !ruby/object:Gem::Version
|
89
|
-
version: '0'
|
90
|
-
type: :development
|
91
|
-
prerelease: false
|
92
|
-
version_requirements: !ruby/object:Gem::Requirement
|
93
|
-
requirements:
|
94
|
-
- - ">="
|
95
|
-
- !ruby/object:Gem::Version
|
96
|
-
version: '0'
|
97
83
|
- !ruby/object:Gem::Dependency
|
98
84
|
name: rake
|
99
85
|
requirement: !ruby/object:Gem::Requirement
|
@@ -122,20 +108,6 @@ dependencies:
|
|
122
108
|
- - "~>"
|
123
109
|
- !ruby/object:Gem::Version
|
124
110
|
version: 3.3.0
|
125
|
-
- !ruby/object:Gem::Dependency
|
126
|
-
name: rubocop
|
127
|
-
requirement: !ruby/object:Gem::Requirement
|
128
|
-
requirements:
|
129
|
-
- - "~>"
|
130
|
-
- !ruby/object:Gem::Version
|
131
|
-
version: 0.34.2
|
132
|
-
type: :development
|
133
|
-
prerelease: false
|
134
|
-
version_requirements: !ruby/object:Gem::Requirement
|
135
|
-
requirements:
|
136
|
-
- - "~>"
|
137
|
-
- !ruby/object:Gem::Version
|
138
|
-
version: 0.34.2
|
139
111
|
- !ruby/object:Gem::Dependency
|
140
112
|
name: simplecov
|
141
113
|
requirement: !ruby/object:Gem::Requirement
|
@@ -177,40 +149,41 @@ files:
|
|
177
149
|
- README.md
|
178
150
|
- Rakefile
|
179
151
|
- lib/formalist.rb
|
180
|
-
- lib/formalist/
|
181
|
-
- lib/formalist/
|
182
|
-
- lib/formalist/
|
183
|
-
- lib/formalist/
|
184
|
-
- lib/formalist/
|
185
|
-
- lib/formalist/
|
152
|
+
- lib/formalist/element.rb
|
153
|
+
- lib/formalist/element/attributes.rb
|
154
|
+
- lib/formalist/element/class_interface.rb
|
155
|
+
- lib/formalist/element/definition.rb
|
156
|
+
- lib/formalist/element/permitted_children.rb
|
157
|
+
- lib/formalist/elements.rb
|
158
|
+
- lib/formalist/elements/attr.rb
|
159
|
+
- lib/formalist/elements/compound_field.rb
|
160
|
+
- lib/formalist/elements/field.rb
|
161
|
+
- lib/formalist/elements/group.rb
|
162
|
+
- lib/formalist/elements/many.rb
|
163
|
+
- lib/formalist/elements/section.rb
|
164
|
+
- lib/formalist/elements/standard.rb
|
165
|
+
- lib/formalist/elements/standard/check_box.rb
|
166
|
+
- lib/formalist/elements/standard/date_field.rb
|
167
|
+
- lib/formalist/elements/standard/date_time_field.rb
|
168
|
+
- lib/formalist/elements/standard/hidden_field.rb
|
169
|
+
- lib/formalist/elements/standard/multi_selection_field.rb
|
170
|
+
- lib/formalist/elements/standard/number_field.rb
|
171
|
+
- lib/formalist/elements/standard/radio_buttons.rb
|
172
|
+
- lib/formalist/elements/standard/select_box.rb
|
173
|
+
- lib/formalist/elements/standard/selection_field.rb
|
174
|
+
- lib/formalist/elements/standard/text_area.rb
|
175
|
+
- lib/formalist/elements/standard/text_field.rb
|
186
176
|
- lib/formalist/form.rb
|
187
|
-
- lib/formalist/form/definition.rb
|
188
|
-
- lib/formalist/form/definition/attr.rb
|
189
|
-
- lib/formalist/form/definition/component.rb
|
190
|
-
- lib/formalist/form/definition/field.rb
|
191
|
-
- lib/formalist/form/definition/group.rb
|
192
|
-
- lib/formalist/form/definition/many.rb
|
193
|
-
- lib/formalist/form/definition/section.rb
|
194
177
|
- lib/formalist/form/definition_context.rb
|
195
178
|
- lib/formalist/form/result.rb
|
196
|
-
- lib/formalist/
|
197
|
-
- lib/formalist/form/result/component.rb
|
198
|
-
- lib/formalist/form/result/field.rb
|
199
|
-
- lib/formalist/form/result/group.rb
|
200
|
-
- lib/formalist/form/result/many.rb
|
201
|
-
- lib/formalist/form/result/section.rb
|
202
|
-
- lib/formalist/form/validated_result.rb
|
203
|
-
- lib/formalist/output_compiler.rb
|
204
|
-
- lib/formalist/validation/collection_rules_compiler.rb
|
205
|
-
- lib/formalist/validation/predicate_list_compiler.rb
|
206
|
-
- lib/formalist/validation/value_rules_compiler.rb
|
179
|
+
- lib/formalist/types.rb
|
207
180
|
- lib/formalist/version.rb
|
208
181
|
- spec/examples.txt
|
209
|
-
- spec/integration/
|
182
|
+
- spec/integration/dependency_injection_spec.rb
|
210
183
|
- spec/integration/form_spec.rb
|
211
|
-
- spec/integration/validation_spec.rb
|
212
184
|
- spec/spec_helper.rb
|
213
|
-
- spec/
|
185
|
+
- spec/support/constants.rb
|
186
|
+
- spec/unit/elements/standard/check_box_spec.rb
|
214
187
|
homepage: https://github.com/icelab/formalist
|
215
188
|
licenses:
|
216
189
|
- MIT
|
@@ -223,7 +196,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
223
196
|
requirements:
|
224
197
|
- - ">="
|
225
198
|
- !ruby/object:Gem::Version
|
226
|
-
version:
|
199
|
+
version: 2.1.0
|
227
200
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
228
201
|
requirements:
|
229
202
|
- - ">="
|
@@ -1,61 +0,0 @@
|
|
1
|
-
require "formalist/form/definition/attr"
|
2
|
-
require "formalist/form/definition/component"
|
3
|
-
require "formalist/form/definition/field"
|
4
|
-
require "formalist/form/definition/group"
|
5
|
-
require "formalist/form/definition/many"
|
6
|
-
require "formalist/form/definition/section"
|
7
|
-
|
8
|
-
module Formalist
|
9
|
-
class DefinitionCompiler
|
10
|
-
attr_reader :display_adapters
|
11
|
-
|
12
|
-
def initialize(display_adapters)
|
13
|
-
@display_adapters = display_adapters
|
14
|
-
end
|
15
|
-
|
16
|
-
def call(ast)
|
17
|
-
ast.map { |node| visit(node) }
|
18
|
-
end
|
19
|
-
|
20
|
-
private
|
21
|
-
|
22
|
-
def visit(node)
|
23
|
-
name, attrs = node
|
24
|
-
send(:"visit_#{name}", attrs)
|
25
|
-
end
|
26
|
-
|
27
|
-
def visit_attr(attrs)
|
28
|
-
name, children = attrs
|
29
|
-
Form::Definition::Attr.new(name, call(children))
|
30
|
-
end
|
31
|
-
|
32
|
-
def visit_component(attrs)
|
33
|
-
display, config, children = attrs
|
34
|
-
|
35
|
-
component = Form::Definition::Component.new(config, call(children))
|
36
|
-
display_adapters[display].call(component)
|
37
|
-
end
|
38
|
-
|
39
|
-
def visit_field(attrs)
|
40
|
-
name, type, display, config = attrs
|
41
|
-
|
42
|
-
field = Form::Definition::Field.new(name, type, display, config)
|
43
|
-
display_adapters[display].call(field)
|
44
|
-
end
|
45
|
-
|
46
|
-
def visit_group(attrs)
|
47
|
-
config, children = attrs
|
48
|
-
Form::Definition::Group.new(config, call(children))
|
49
|
-
end
|
50
|
-
|
51
|
-
def visit_many(attrs)
|
52
|
-
name, config, children = attrs
|
53
|
-
Form::Definition::Many.new(name, config, call(children))
|
54
|
-
end
|
55
|
-
|
56
|
-
def visit_section(attrs)
|
57
|
-
name, config, children = attrs
|
58
|
-
Form::Definition::Section.new(name, config, call(children))
|
59
|
-
end
|
60
|
-
end
|
61
|
-
end
|
@@ -1,19 +0,0 @@
|
|
1
|
-
module Formalist
|
2
|
-
class DisplayAdapters
|
3
|
-
class Radio
|
4
|
-
PERMITTED_TYPES = %w[
|
5
|
-
decimal
|
6
|
-
float
|
7
|
-
int
|
8
|
-
string
|
9
|
-
].freeze
|
10
|
-
|
11
|
-
def call(field)
|
12
|
-
raise ArgumentError, "field type must be one of #{PERMITTED_TYPES.join(', ')}" unless PERMITTED_TYPES.include?(field.type)
|
13
|
-
raise ArgumentError, "field must have +option_values+ config" unless field.config.keys.include?(:option_values)
|
14
|
-
|
15
|
-
field.to_display_variant("radio")
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
@@ -1,19 +0,0 @@
|
|
1
|
-
module Formalist
|
2
|
-
class DisplayAdapters
|
3
|
-
class Select
|
4
|
-
PERMITTED_TYPES = %w[
|
5
|
-
decimal
|
6
|
-
float
|
7
|
-
int
|
8
|
-
string
|
9
|
-
].freeze
|
10
|
-
|
11
|
-
def call(field)
|
12
|
-
raise ArgumentError, "field type must be one of #{PERMITTED_TYPES.join(', ')}" unless PERMITTED_TYPES.include?(field.type)
|
13
|
-
raise ArgumentError, "field must have +option_values+ config" unless field.config.keys.include?(:option_values)
|
14
|
-
|
15
|
-
field.to_display_variant("select")
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
@@ -1,14 +0,0 @@
|
|
1
|
-
module Formalist
|
2
|
-
class DisplayAdapters
|
3
|
-
class Textarea
|
4
|
-
PERMITTED_TYPES = %w[
|
5
|
-
string
|
6
|
-
].freeze
|
7
|
-
|
8
|
-
def call(field)
|
9
|
-
raise ArgumentError, "field type must be one of #{PERMITTED_TYPES.join(', ')}" unless PERMITTED_TYPES.include?(field.type)
|
10
|
-
field.to_display_variant("textarea")
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|