simple_form 3.0.1 → 3.1.0.rc1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +33 -27
- data/MIT-LICENSE +1 -1
- data/README.md +146 -71
- data/lib/generators/simple_form/install_generator.rb +2 -2
- data/lib/generators/simple_form/templates/README +3 -4
- data/lib/generators/simple_form/templates/config/initializers/simple_form.rb +19 -3
- data/lib/generators/simple_form/templates/config/initializers/simple_form_bootstrap.rb +83 -22
- data/lib/generators/simple_form/templates/config/initializers/simple_form_foundation.rb +1 -1
- data/lib/generators/simple_form/templates/config/locales/simple_form.en.yml +7 -2
- data/lib/simple_form/action_view_extensions/form_helper.rb +1 -1
- data/lib/simple_form/components/errors.rb +30 -2
- data/lib/simple_form/components/hints.rb +2 -2
- data/lib/simple_form/components/html5.rb +1 -1
- data/lib/simple_form/components/label_input.rb +20 -2
- data/lib/simple_form/components/labels.rb +9 -5
- data/lib/simple_form/components/maxlength.rb +1 -1
- data/lib/simple_form/components/min_max.rb +1 -1
- data/lib/simple_form/components/pattern.rb +1 -1
- data/lib/simple_form/components/placeholders.rb +2 -2
- data/lib/simple_form/components/readonly.rb +1 -1
- data/lib/simple_form/form_builder.rb +92 -57
- data/lib/simple_form/helpers.rb +5 -5
- data/lib/simple_form/inputs/base.rb +33 -11
- data/lib/simple_form/inputs/block_input.rb +1 -1
- data/lib/simple_form/inputs/boolean_input.rb +23 -13
- data/lib/simple_form/inputs/collection_input.rb +32 -9
- data/lib/simple_form/inputs/collection_radio_buttons_input.rb +6 -11
- data/lib/simple_form/inputs/collection_select_input.rb +4 -2
- data/lib/simple_form/inputs/date_time_input.rb +12 -2
- data/lib/simple_form/inputs/file_input.rb +4 -2
- data/lib/simple_form/inputs/grouped_collection_select_input.rb +15 -3
- data/lib/simple_form/inputs/hidden_input.rb +4 -2
- data/lib/simple_form/inputs/numeric_input.rb +5 -4
- data/lib/simple_form/inputs/password_input.rb +4 -2
- data/lib/simple_form/inputs/priority_input.rb +4 -2
- data/lib/simple_form/inputs/range_input.rb +1 -1
- data/lib/simple_form/inputs/string_input.rb +4 -2
- data/lib/simple_form/inputs/text_input.rb +4 -2
- data/lib/simple_form/railtie.rb +7 -0
- data/lib/simple_form/tags.rb +7 -0
- data/lib/simple_form/version.rb +1 -1
- data/lib/simple_form/wrappers/builder.rb +5 -5
- data/lib/simple_form/wrappers/leaf.rb +28 -0
- data/lib/simple_form/wrappers/many.rb +5 -6
- data/lib/simple_form/wrappers/root.rb +1 -1
- data/lib/simple_form/wrappers/single.rb +5 -3
- data/lib/simple_form/wrappers.rb +1 -0
- data/lib/simple_form.rb +38 -6
- data/test/action_view_extensions/builder_test.rb +2 -2
- data/test/components/label_test.rb +1 -1
- data/test/form_builder/association_test.rb +17 -0
- data/test/form_builder/error_notification_test.rb +1 -1
- data/test/form_builder/error_test.rb +61 -0
- data/test/form_builder/input_field_test.rb +25 -1
- data/test/form_builder/label_test.rb +24 -1
- data/test/form_builder/wrapper_test.rb +67 -0
- data/test/generators/simple_form_generator_test.rb +2 -2
- data/test/inputs/boolean_input_test.rb +50 -2
- data/test/inputs/collection_check_boxes_input_test.rb +40 -11
- data/test/inputs/collection_radio_buttons_input_test.rb +76 -17
- data/test/inputs/collection_select_input_test.rb +108 -3
- data/test/inputs/datetime_input_test.rb +105 -38
- data/test/inputs/discovery_test.rb +12 -1
- data/test/inputs/grouped_collection_select_input_test.rb +36 -0
- data/test/inputs/string_input_test.rb +20 -0
- data/test/simple_form_test.rb +8 -0
- data/test/support/discovery_inputs.rb +12 -2
- data/test/support/misc_helpers.rb +49 -5
- data/test/support/models.rb +49 -24
- data/test/test_helper.rb +2 -0
- metadata +23 -34
|
@@ -46,12 +46,12 @@ module MiscHelpers
|
|
|
46
46
|
end
|
|
47
47
|
end
|
|
48
48
|
|
|
49
|
-
def swap_wrapper(name
|
|
50
|
-
old = SimpleForm.wrappers[name]
|
|
51
|
-
SimpleForm.wrappers[name] = wrapper
|
|
49
|
+
def swap_wrapper(name = :default, wrapper = self.custom_wrapper)
|
|
50
|
+
old = SimpleForm.wrappers[name.to_s]
|
|
51
|
+
SimpleForm.wrappers[name.to_s] = wrapper
|
|
52
52
|
yield
|
|
53
53
|
ensure
|
|
54
|
-
SimpleForm.wrappers[name] = old
|
|
54
|
+
SimpleForm.wrappers[name.to_s] = old
|
|
55
55
|
end
|
|
56
56
|
|
|
57
57
|
def custom_wrapper
|
|
@@ -68,6 +68,32 @@ module MiscHelpers
|
|
|
68
68
|
end
|
|
69
69
|
end
|
|
70
70
|
|
|
71
|
+
def custom_wrapper_with_input_class
|
|
72
|
+
SimpleForm.build tag: :div, class: "custom_wrapper" do |b|
|
|
73
|
+
b.use :label
|
|
74
|
+
b.use :input, class: 'inline-class'
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
def custom_wrapper_with_label_class
|
|
79
|
+
SimpleForm.build tag: :div, class: "custom_wrapper" do |b|
|
|
80
|
+
b.use :label, class: 'inline-class'
|
|
81
|
+
b.use :input
|
|
82
|
+
end
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
def custom_wrapper_with_input_attributes
|
|
86
|
+
SimpleForm.build tag: :div, class: "custom_wrapper" do |b|
|
|
87
|
+
b.use :input, data: { modal: true }
|
|
88
|
+
end
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
def custom_wrapper_with_label_input_class
|
|
92
|
+
SimpleForm.build tag: :div, class: "custom_wrapper" do |b|
|
|
93
|
+
b.use :label_input, class: 'inline-class'
|
|
94
|
+
end
|
|
95
|
+
end
|
|
96
|
+
|
|
71
97
|
def custom_wrapper_with_wrapped_input
|
|
72
98
|
SimpleForm.build tag: :div, class: "custom_wrapper" do |b|
|
|
73
99
|
b.wrapper tag: :div, class: 'elem' do |component|
|
|
@@ -112,6 +138,24 @@ module MiscHelpers
|
|
|
112
138
|
end
|
|
113
139
|
end
|
|
114
140
|
|
|
141
|
+
def custom_wrapper_with_additional_attributes
|
|
142
|
+
SimpleForm.build tag: :div, class: 'custom_wrapper', html: { data: { wrapper: :test }, title: 'some title' } do |b|
|
|
143
|
+
b.use :label_input
|
|
144
|
+
end
|
|
145
|
+
end
|
|
146
|
+
|
|
147
|
+
def custom_wrapper_with_full_error
|
|
148
|
+
SimpleForm.build tag: :div, class: 'custom_wrapper' do |b|
|
|
149
|
+
b.use :full_error, wrap_with: { tag: :span, class: :error }
|
|
150
|
+
end
|
|
151
|
+
end
|
|
152
|
+
|
|
153
|
+
def custom_wrapper_with_label_text
|
|
154
|
+
SimpleForm.build :label_text => proc { |label, required| "**#{label}**" } do |b|
|
|
155
|
+
b.use :label_input
|
|
156
|
+
end
|
|
157
|
+
end
|
|
158
|
+
|
|
115
159
|
def custom_form_for(object, *args, &block)
|
|
116
160
|
simple_form_for(object, *args, { builder: CustomFormBuilder }, &block)
|
|
117
161
|
end
|
|
@@ -142,7 +186,7 @@ module MiscHelpers
|
|
|
142
186
|
end
|
|
143
187
|
end
|
|
144
188
|
|
|
145
|
-
def with_input_for(object, attribute_name, type, options={})
|
|
189
|
+
def with_input_for(object, attribute_name, type, options = {})
|
|
146
190
|
with_concat_form_for(object) do |f|
|
|
147
191
|
f.input(attribute_name, options.merge(as: type))
|
|
148
192
|
end
|
data/test/support/models.rb
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
Association = Struct.new(:klass, :name, :macro, :options)
|
|
1
|
+
Association = Struct.new(:klass, :name, :macro, :scope, :options)
|
|
2
2
|
|
|
3
3
|
Column = Struct.new(:name, :type, :limit) do
|
|
4
4
|
# Returns +true+ if the column is either of type integer, float or decimal.
|
|
@@ -7,16 +7,36 @@ Column = Struct.new(:name, :type, :limit) do
|
|
|
7
7
|
end
|
|
8
8
|
end
|
|
9
9
|
|
|
10
|
-
Relation = Struct.new(:
|
|
10
|
+
Relation = Struct.new(:records) do
|
|
11
|
+
delegate :each, to: :records
|
|
12
|
+
|
|
11
13
|
def where(conditions = nil)
|
|
12
|
-
self.class.new conditions ?
|
|
14
|
+
self.class.new conditions ? records.first : records
|
|
13
15
|
end
|
|
14
16
|
|
|
15
17
|
def order(conditions = nil)
|
|
16
|
-
self.class.new conditions ?
|
|
18
|
+
self.class.new conditions ? records.last : records
|
|
17
19
|
end
|
|
18
20
|
|
|
19
|
-
alias_method :to_a,
|
|
21
|
+
alias_method :to_a, :records
|
|
22
|
+
alias_method :to_ary, :records
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
Picture = Struct.new(:id, :name) do
|
|
26
|
+
extend ActiveModel::Naming
|
|
27
|
+
include ActiveModel::Conversion
|
|
28
|
+
|
|
29
|
+
def self.where(conditions = nil)
|
|
30
|
+
if conditions.is_a?(Hash) && conditions[:name]
|
|
31
|
+
all.to_a.last
|
|
32
|
+
else
|
|
33
|
+
all
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def self.all
|
|
38
|
+
Relation.new((1..3).map { |i| new(i, "#{name} #{i}") })
|
|
39
|
+
end
|
|
20
40
|
end
|
|
21
41
|
|
|
22
42
|
Company = Struct.new(:id, :name) do
|
|
@@ -28,11 +48,11 @@ Company = Struct.new(:id, :name) do
|
|
|
28
48
|
end
|
|
29
49
|
|
|
30
50
|
def self._relation
|
|
31
|
-
|
|
51
|
+
all
|
|
32
52
|
end
|
|
33
53
|
|
|
34
54
|
def self.all
|
|
35
|
-
(1..3).map { |i| new(i, "#{name} #{i}") }
|
|
55
|
+
Relation.new((1..3).map { |i| new(i, "#{name} #{i}") })
|
|
36
56
|
end
|
|
37
57
|
|
|
38
58
|
def persisted?
|
|
@@ -53,7 +73,8 @@ class User
|
|
|
53
73
|
:delivery_time, :born_at, :special_company_id, :country, :tags, :tag_ids,
|
|
54
74
|
:avatar, :home_picture, :email, :status, :residence_country, :phone_number,
|
|
55
75
|
:post_count, :lock_version, :amount, :attempts, :action, :credit_card, :gender,
|
|
56
|
-
:extra_special_company_id
|
|
76
|
+
:extra_special_company_id, :pictures, :picture_ids, :special_pictures,
|
|
77
|
+
:special_picture_ids
|
|
57
78
|
|
|
58
79
|
def self.build(extra_attributes = {})
|
|
59
80
|
attributes = {
|
|
@@ -66,7 +87,7 @@ class User
|
|
|
66
87
|
new attributes
|
|
67
88
|
end
|
|
68
89
|
|
|
69
|
-
def initialize(options={})
|
|
90
|
+
def initialize(options = {})
|
|
70
91
|
@new_record = false
|
|
71
92
|
options.each do |key, value|
|
|
72
93
|
send("#{key}=", value)
|
|
@@ -108,7 +129,7 @@ class User
|
|
|
108
129
|
Column.new(attribute, column_type, limit)
|
|
109
130
|
end
|
|
110
131
|
|
|
111
|
-
def self.human_attribute_name(attribute)
|
|
132
|
+
def self.human_attribute_name(attribute, options = {})
|
|
112
133
|
case attribute
|
|
113
134
|
when 'name'
|
|
114
135
|
'Super User Name!'
|
|
@@ -117,35 +138,39 @@ class User
|
|
|
117
138
|
when 'company'
|
|
118
139
|
'Company Human Name!'
|
|
119
140
|
else
|
|
120
|
-
attribute.humanize
|
|
141
|
+
attribute.to_s.humanize
|
|
121
142
|
end
|
|
122
143
|
end
|
|
123
144
|
|
|
124
145
|
def self.reflect_on_association(association)
|
|
125
146
|
case association
|
|
126
147
|
when :company
|
|
127
|
-
Association.new(Company, association, :belongs_to, {})
|
|
148
|
+
Association.new(Company, association, :belongs_to, nil, {})
|
|
128
149
|
when :tags
|
|
129
|
-
Association.new(Tag, association, :has_many, {})
|
|
150
|
+
Association.new(Tag, association, :has_many, nil, {})
|
|
130
151
|
when :first_company
|
|
131
|
-
Association.new(Company, association, :has_one, {})
|
|
152
|
+
Association.new(Company, association, :has_one, nil, {})
|
|
132
153
|
when :special_company
|
|
133
|
-
Association.new(Company, association, :belongs_to, { conditions: { id: 1 } })
|
|
154
|
+
Association.new(Company, association, :belongs_to, nil, { conditions: { id: 1 } })
|
|
134
155
|
when :extra_special_company
|
|
135
|
-
Association.new(Company, association, :belongs_to, { conditions: proc { { id:
|
|
156
|
+
Association.new(Company, association, :belongs_to, nil, { conditions: proc { { id: self.id } } })
|
|
157
|
+
when :pictures
|
|
158
|
+
Association.new(Picture, association, :has_many, nil, {})
|
|
159
|
+
when :special_pictures
|
|
160
|
+
Association.new(Picture, association, :has_many, proc { where(name: self.name) }, {})
|
|
136
161
|
end
|
|
137
162
|
end
|
|
138
163
|
|
|
139
164
|
def errors
|
|
140
165
|
@errors ||= begin
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
166
|
+
errors = ActiveModel::Errors.new(self)
|
|
167
|
+
errors.add(:name, "can't be blank")
|
|
168
|
+
errors.add(:description, 'must be longer than 15 characters')
|
|
169
|
+
errors.add(:age, 'is not a number')
|
|
170
|
+
errors.add(:age, 'must be greater than 18')
|
|
171
|
+
errors.add(:company, 'company must be present')
|
|
172
|
+
errors.add(:company_id, 'must be valid')
|
|
173
|
+
errors
|
|
149
174
|
end
|
|
150
175
|
end
|
|
151
176
|
|
data/test/test_helper.rb
CHANGED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: simple_form
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 3.0.
|
|
4
|
+
version: 3.1.0.rc1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- José Valim
|
|
@@ -10,50 +10,38 @@ authors:
|
|
|
10
10
|
autorequire:
|
|
11
11
|
bindir: bin
|
|
12
12
|
cert_chain: []
|
|
13
|
-
date:
|
|
13
|
+
date: 2014-04-14 00:00:00.000000000 Z
|
|
14
14
|
dependencies:
|
|
15
15
|
- !ruby/object:Gem::Dependency
|
|
16
16
|
name: activemodel
|
|
17
17
|
requirement: !ruby/object:Gem::Requirement
|
|
18
18
|
requirements:
|
|
19
|
-
- -
|
|
19
|
+
- - "~>"
|
|
20
20
|
- !ruby/object:Gem::Version
|
|
21
|
-
version: 4.0
|
|
22
|
-
- - <
|
|
23
|
-
- !ruby/object:Gem::Version
|
|
24
|
-
version: '4.1'
|
|
21
|
+
version: '4.0'
|
|
25
22
|
type: :runtime
|
|
26
23
|
prerelease: false
|
|
27
24
|
version_requirements: !ruby/object:Gem::Requirement
|
|
28
25
|
requirements:
|
|
29
|
-
- -
|
|
30
|
-
- !ruby/object:Gem::Version
|
|
31
|
-
version: 4.0.0
|
|
32
|
-
- - <
|
|
26
|
+
- - "~>"
|
|
33
27
|
- !ruby/object:Gem::Version
|
|
34
|
-
version: '4.
|
|
28
|
+
version: '4.0'
|
|
35
29
|
- !ruby/object:Gem::Dependency
|
|
36
30
|
name: actionpack
|
|
37
31
|
requirement: !ruby/object:Gem::Requirement
|
|
38
32
|
requirements:
|
|
39
|
-
- -
|
|
40
|
-
- !ruby/object:Gem::Version
|
|
41
|
-
version: 4.0.0
|
|
42
|
-
- - <
|
|
33
|
+
- - "~>"
|
|
43
34
|
- !ruby/object:Gem::Version
|
|
44
|
-
version: '4.
|
|
35
|
+
version: '4.0'
|
|
45
36
|
type: :runtime
|
|
46
37
|
prerelease: false
|
|
47
38
|
version_requirements: !ruby/object:Gem::Requirement
|
|
48
39
|
requirements:
|
|
49
|
-
- -
|
|
40
|
+
- - "~>"
|
|
50
41
|
- !ruby/object:Gem::Version
|
|
51
|
-
version: 4.0
|
|
52
|
-
- - <
|
|
53
|
-
- !ruby/object:Gem::Version
|
|
54
|
-
version: '4.1'
|
|
42
|
+
version: '4.0'
|
|
55
43
|
description: Forms made easy!
|
|
56
|
-
email:
|
|
44
|
+
email: opensource@plataformatec.com.br
|
|
57
45
|
executables: []
|
|
58
46
|
extensions: []
|
|
59
47
|
extra_rdoc_files: []
|
|
@@ -61,7 +49,9 @@ files:
|
|
|
61
49
|
- CHANGELOG.md
|
|
62
50
|
- MIT-LICENSE
|
|
63
51
|
- README.md
|
|
52
|
+
- lib/generators/simple_form/USAGE
|
|
64
53
|
- lib/generators/simple_form/install_generator.rb
|
|
54
|
+
- lib/generators/simple_form/templates/README
|
|
65
55
|
- lib/generators/simple_form/templates/_form.html.erb
|
|
66
56
|
- lib/generators/simple_form/templates/_form.html.haml
|
|
67
57
|
- lib/generators/simple_form/templates/_form.html.slim
|
|
@@ -69,10 +59,10 @@ files:
|
|
|
69
59
|
- lib/generators/simple_form/templates/config/initializers/simple_form_bootstrap.rb
|
|
70
60
|
- lib/generators/simple_form/templates/config/initializers/simple_form_foundation.rb
|
|
71
61
|
- lib/generators/simple_form/templates/config/locales/simple_form.en.yml
|
|
72
|
-
- lib/
|
|
73
|
-
- lib/generators/simple_form/USAGE
|
|
62
|
+
- lib/simple_form.rb
|
|
74
63
|
- lib/simple_form/action_view_extensions/builder.rb
|
|
75
64
|
- lib/simple_form/action_view_extensions/form_helper.rb
|
|
65
|
+
- lib/simple_form/components.rb
|
|
76
66
|
- lib/simple_form/components/errors.rb
|
|
77
67
|
- lib/simple_form/components/hints.rb
|
|
78
68
|
- lib/simple_form/components/html5.rb
|
|
@@ -83,16 +73,16 @@ files:
|
|
|
83
73
|
- lib/simple_form/components/pattern.rb
|
|
84
74
|
- lib/simple_form/components/placeholders.rb
|
|
85
75
|
- lib/simple_form/components/readonly.rb
|
|
86
|
-
- lib/simple_form/components.rb
|
|
87
76
|
- lib/simple_form/error_notification.rb
|
|
88
77
|
- lib/simple_form/form_builder.rb
|
|
78
|
+
- lib/simple_form/helpers.rb
|
|
89
79
|
- lib/simple_form/helpers/autofocus.rb
|
|
90
80
|
- lib/simple_form/helpers/disabled.rb
|
|
91
81
|
- lib/simple_form/helpers/readonly.rb
|
|
92
82
|
- lib/simple_form/helpers/required.rb
|
|
93
83
|
- lib/simple_form/helpers/validators.rb
|
|
94
|
-
- lib/simple_form/helpers.rb
|
|
95
84
|
- lib/simple_form/i18n_cache.rb
|
|
85
|
+
- lib/simple_form/inputs.rb
|
|
96
86
|
- lib/simple_form/inputs/base.rb
|
|
97
87
|
- lib/simple_form/inputs/block_input.rb
|
|
98
88
|
- lib/simple_form/inputs/boolean_input.rb
|
|
@@ -110,17 +100,16 @@ files:
|
|
|
110
100
|
- lib/simple_form/inputs/range_input.rb
|
|
111
101
|
- lib/simple_form/inputs/string_input.rb
|
|
112
102
|
- lib/simple_form/inputs/text_input.rb
|
|
113
|
-
- lib/simple_form/inputs.rb
|
|
114
103
|
- lib/simple_form/map_type.rb
|
|
115
104
|
- lib/simple_form/railtie.rb
|
|
116
105
|
- lib/simple_form/tags.rb
|
|
117
106
|
- lib/simple_form/version.rb
|
|
107
|
+
- lib/simple_form/wrappers.rb
|
|
118
108
|
- lib/simple_form/wrappers/builder.rb
|
|
109
|
+
- lib/simple_form/wrappers/leaf.rb
|
|
119
110
|
- lib/simple_form/wrappers/many.rb
|
|
120
111
|
- lib/simple_form/wrappers/root.rb
|
|
121
112
|
- lib/simple_form/wrappers/single.rb
|
|
122
|
-
- lib/simple_form/wrappers.rb
|
|
123
|
-
- lib/simple_form.rb
|
|
124
113
|
- test/action_view_extensions/builder_test.rb
|
|
125
114
|
- test/action_view_extensions/form_helper_test.rb
|
|
126
115
|
- test/components/label_test.rb
|
|
@@ -167,17 +156,17 @@ require_paths:
|
|
|
167
156
|
- lib
|
|
168
157
|
required_ruby_version: !ruby/object:Gem::Requirement
|
|
169
158
|
requirements:
|
|
170
|
-
- -
|
|
159
|
+
- - ">="
|
|
171
160
|
- !ruby/object:Gem::Version
|
|
172
161
|
version: '0'
|
|
173
162
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
174
163
|
requirements:
|
|
175
|
-
- -
|
|
164
|
+
- - ">"
|
|
176
165
|
- !ruby/object:Gem::Version
|
|
177
|
-
version:
|
|
166
|
+
version: 1.3.1
|
|
178
167
|
requirements: []
|
|
179
168
|
rubyforge_project: simple_form
|
|
180
|
-
rubygems_version: 2.
|
|
169
|
+
rubygems_version: 2.2.2
|
|
181
170
|
signing_key:
|
|
182
171
|
specification_version: 4
|
|
183
172
|
summary: Forms made easy!
|