simple_form 4.0.1 → 5.1.0
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 +5 -5
- data/CHANGELOG.md +68 -8
- data/MIT-LICENSE +2 -1
- data/README.md +47 -51
- data/lib/generators/simple_form/templates/README +2 -3
- data/lib/generators/simple_form/templates/config/initializers/simple_form.rb +1 -7
- data/lib/generators/simple_form/templates/config/initializers/simple_form_bootstrap.rb +26 -25
- data/lib/generators/simple_form/templates/config/initializers/simple_form_foundation.rb +1 -1
- data/lib/simple_form.rb +22 -5
- data/lib/simple_form/components/errors.rb +5 -1
- data/lib/simple_form/components/labels.rb +3 -5
- data/lib/simple_form/components/maxlength.rb +0 -4
- data/lib/simple_form/components/minlength.rb +0 -4
- data/lib/simple_form/form_builder.rb +30 -10
- data/lib/simple_form/inputs.rb +2 -0
- data/lib/simple_form/inputs/base.rb +4 -4
- data/lib/simple_form/inputs/boolean_input.rb +1 -0
- data/lib/simple_form/inputs/collection_check_boxes_input.rb +1 -1
- data/lib/simple_form/inputs/collection_input.rb +3 -5
- data/lib/simple_form/inputs/color_input.rb +14 -0
- data/lib/simple_form/inputs/priority_input.rb +0 -4
- data/lib/simple_form/inputs/rich_text_area_input.rb +12 -0
- data/lib/simple_form/inputs/string_input.rb +1 -1
- data/lib/simple_form/tags.rb +6 -2
- data/lib/simple_form/version.rb +1 -1
- data/lib/simple_form/wrappers/root.rb +8 -3
- data/test/action_view_extensions/builder_test.rb +22 -4
- data/test/components/label_test.rb +0 -4
- data/test/form_builder/association_test.rb +6 -0
- data/test/form_builder/error_test.rb +6 -0
- data/test/form_builder/general_test.rb +23 -19
- data/test/form_builder/input_field_test.rb +3 -9
- data/test/form_builder/label_test.rb +1 -1
- data/test/form_builder/wrapper_test.rb +8 -1
- data/test/inputs/boolean_input_test.rb +8 -0
- data/test/inputs/collection_check_boxes_input_test.rb +8 -4
- data/test/inputs/collection_radio_buttons_input_test.rb +8 -4
- data/test/inputs/collection_select_input_test.rb +6 -4
- data/test/inputs/color_input_test.rb +10 -0
- data/test/inputs/datetime_input_test.rb +2 -12
- data/test/inputs/disabled_test.rb +13 -0
- data/test/inputs/discovery_test.rb +21 -0
- data/test/inputs/priority_input_test.rb +6 -14
- data/test/inputs/rich_text_area_input_test.rb +15 -0
- data/test/inputs/string_input_test.rb +8 -15
- data/test/support/discovery_inputs.rb +7 -0
- data/test/support/misc_helpers.rb +8 -2
- data/test/support/models.rb +29 -6
- data/test/test_helper.rb +7 -4
- metadata +44 -40
- data/lib/simple_form/i18n_cache.rb +0 -23
@@ -37,6 +37,13 @@ class CollectionSelectInput < SimpleForm::Inputs::CollectionSelectInput
|
|
37
37
|
end
|
38
38
|
end
|
39
39
|
|
40
|
+
class FileInput < SimpleForm::Inputs::FileInput
|
41
|
+
def input_html_classes
|
42
|
+
super.delete_if { |html_class| html_class == :file }
|
43
|
+
super.push('file-upload')
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
40
47
|
module CustomInputs
|
41
48
|
class CustomizedInput < SimpleForm::Inputs::StringInput
|
42
49
|
def input_html_classes
|
@@ -213,8 +213,8 @@ module MiscHelpers
|
|
213
213
|
end
|
214
214
|
end
|
215
215
|
|
216
|
-
def custom_wrapper_with_input_valid_class
|
217
|
-
SimpleForm.build tag: :div, class: "custom_wrapper", valid_class:
|
216
|
+
def custom_wrapper_with_input_valid_class(valid_class: :field_without_errors)
|
217
|
+
SimpleForm.build tag: :div, class: "custom_wrapper", valid_class: valid_class do |b|
|
218
218
|
b.use :label
|
219
219
|
b.use :input, class: 'inline-class', valid_class: 'is-valid'
|
220
220
|
end
|
@@ -255,6 +255,12 @@ module MiscHelpers
|
|
255
255
|
f.input(attribute_name, options.merge(as: type))
|
256
256
|
end
|
257
257
|
end
|
258
|
+
|
259
|
+
def with_input_field_for(object, *args)
|
260
|
+
with_concat_form_for(object) do |f|
|
261
|
+
f.input_field(*args)
|
262
|
+
end
|
263
|
+
end
|
258
264
|
end
|
259
265
|
|
260
266
|
class CustomFormBuilder < SimpleForm::FormBuilder
|
data/test/support/models.rb
CHANGED
@@ -76,7 +76,11 @@ Friend = Struct.new(:id, :name) do
|
|
76
76
|
end
|
77
77
|
end
|
78
78
|
|
79
|
-
class Tag < Company
|
79
|
+
class Tag < Company
|
80
|
+
def group_method
|
81
|
+
["category-1"]
|
82
|
+
end
|
83
|
+
end
|
80
84
|
|
81
85
|
TagGroup = Struct.new(:id, :name, :tags)
|
82
86
|
|
@@ -91,7 +95,7 @@ class User
|
|
91
95
|
:post_count, :lock_version, :amount, :attempts, :action, :credit_card, :gender,
|
92
96
|
:extra_special_company_id, :pictures, :picture_ids, :special_pictures,
|
93
97
|
:special_picture_ids, :uuid, :friends, :friend_ids, :special_tags, :special_tag_ids,
|
94
|
-
:citext, :hstore, :json, :jsonb
|
98
|
+
:citext, :hstore, :json, :jsonb, :hourly, :favorite_color
|
95
99
|
|
96
100
|
def self.build(extra_attributes = {})
|
97
101
|
attributes = {
|
@@ -200,7 +204,7 @@ class User
|
|
200
204
|
|
201
205
|
def self.human_attribute_name(attribute, options = {})
|
202
206
|
case attribute
|
203
|
-
when 'name'
|
207
|
+
when 'name', :name
|
204
208
|
'Super User Name!'
|
205
209
|
when 'description'
|
206
210
|
'User Description!'
|
@@ -277,9 +281,6 @@ class ValidatingUser < User
|
|
277
281
|
only_integer: true
|
278
282
|
validates_length_of :name, maximum: 25, minimum: 5
|
279
283
|
validates_length_of :description, in: 15..50
|
280
|
-
if ActionPack::VERSION::STRING < '5'
|
281
|
-
validates_length_of :action, maximum: 10, tokenizer: ->(str) { str.scan(/\w+/) }
|
282
|
-
end
|
283
284
|
validates_length_of :home_picture, is: 12
|
284
285
|
|
285
286
|
def min_amount
|
@@ -332,3 +333,25 @@ end
|
|
332
333
|
|
333
334
|
class UserNumber1And2 < User
|
334
335
|
end
|
336
|
+
|
337
|
+
class UserWithAttachment < User
|
338
|
+
def avatar_attachment
|
339
|
+
OpenStruct.new
|
340
|
+
end
|
341
|
+
|
342
|
+
def avatars_attachments
|
343
|
+
OpenStruct.new
|
344
|
+
end
|
345
|
+
|
346
|
+
def remote_cover_url
|
347
|
+
"/uploads/cover.png"
|
348
|
+
end
|
349
|
+
|
350
|
+
def profile_image_attacher
|
351
|
+
OpenStruct.new
|
352
|
+
end
|
353
|
+
|
354
|
+
def portrait_file_name
|
355
|
+
"portrait.png"
|
356
|
+
end
|
357
|
+
end
|
data/test/test_helper.rb
CHANGED
@@ -1,15 +1,13 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
-
require 'bundler/setup'
|
3
|
-
|
4
2
|
require 'minitest/autorun'
|
5
3
|
|
6
4
|
require 'active_model'
|
7
5
|
require 'action_controller'
|
8
6
|
require 'action_view'
|
7
|
+
|
9
8
|
ActionView::RoutingUrlFor.send(:include, ActionDispatch::Routing::UrlFor)
|
10
9
|
|
11
10
|
require 'action_view/template'
|
12
|
-
|
13
11
|
require 'action_view/test_case'
|
14
12
|
|
15
13
|
module Rails
|
@@ -41,10 +39,14 @@ if ActiveSupport::TestCase.respond_to?(:test_order=)
|
|
41
39
|
ActiveSupport::TestCase.test_order = :random
|
42
40
|
end
|
43
41
|
|
42
|
+
require "rails/test_unit/line_filtering"
|
43
|
+
|
44
44
|
class ActionView::TestCase
|
45
45
|
include MiscHelpers
|
46
46
|
include SimpleForm::ActionViewExtensions::FormHelper
|
47
47
|
|
48
|
+
extend Rails::LineFiltering
|
49
|
+
|
48
50
|
setup :set_controller
|
49
51
|
setup :setup_users
|
50
52
|
|
@@ -58,7 +60,7 @@ class ActionView::TestCase
|
|
58
60
|
|
59
61
|
@validating_user = ValidatingUser.build({
|
60
62
|
name: 'Tester McTesterson',
|
61
|
-
description: 'A test user of the most
|
63
|
+
description: 'A test user of the most distinguished caliber',
|
62
64
|
home_picture: 'Home picture',
|
63
65
|
age: 19,
|
64
66
|
amount: 15,
|
@@ -89,4 +91,5 @@ class ActionView::TestCase
|
|
89
91
|
alias :validating_user_path :user_path
|
90
92
|
alias :validating_users_path :user_path
|
91
93
|
alias :other_validating_user_path :user_path
|
94
|
+
alias :user_with_attachment_path :user_path
|
92
95
|
end
|
metadata
CHANGED
@@ -1,16 +1,16 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: simple_form
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 5.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- José Valim
|
8
8
|
- Carlos Antônio
|
9
9
|
- Rafael França
|
10
|
-
autorequire:
|
10
|
+
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date:
|
13
|
+
date: 2021-02-09 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: activemodel
|
@@ -18,30 +18,30 @@ dependencies:
|
|
18
18
|
requirements:
|
19
19
|
- - ">="
|
20
20
|
- !ruby/object:Gem::Version
|
21
|
-
version: '5.
|
21
|
+
version: '5.2'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
24
|
version_requirements: !ruby/object:Gem::Requirement
|
25
25
|
requirements:
|
26
26
|
- - ">="
|
27
27
|
- !ruby/object:Gem::Version
|
28
|
-
version: '5.
|
28
|
+
version: '5.2'
|
29
29
|
- !ruby/object:Gem::Dependency
|
30
30
|
name: actionpack
|
31
31
|
requirement: !ruby/object:Gem::Requirement
|
32
32
|
requirements:
|
33
33
|
- - ">="
|
34
34
|
- !ruby/object:Gem::Version
|
35
|
-
version: '5.
|
35
|
+
version: '5.2'
|
36
36
|
type: :runtime
|
37
37
|
prerelease: false
|
38
38
|
version_requirements: !ruby/object:Gem::Requirement
|
39
39
|
requirements:
|
40
40
|
- - ">="
|
41
41
|
- !ruby/object:Gem::Version
|
42
|
-
version: '5.
|
42
|
+
version: '5.2'
|
43
43
|
description: Forms made easy!
|
44
|
-
email:
|
44
|
+
email: heartcombo@googlegroups.com
|
45
45
|
executables: []
|
46
46
|
extensions: []
|
47
47
|
extra_rdoc_files: []
|
@@ -82,7 +82,6 @@ files:
|
|
82
82
|
- lib/simple_form/helpers/readonly.rb
|
83
83
|
- lib/simple_form/helpers/required.rb
|
84
84
|
- lib/simple_form/helpers/validators.rb
|
85
|
-
- lib/simple_form/i18n_cache.rb
|
86
85
|
- lib/simple_form/inputs.rb
|
87
86
|
- lib/simple_form/inputs/base.rb
|
88
87
|
- lib/simple_form/inputs/block_input.rb
|
@@ -91,6 +90,7 @@ files:
|
|
91
90
|
- lib/simple_form/inputs/collection_input.rb
|
92
91
|
- lib/simple_form/inputs/collection_radio_buttons_input.rb
|
93
92
|
- lib/simple_form/inputs/collection_select_input.rb
|
93
|
+
- lib/simple_form/inputs/color_input.rb
|
94
94
|
- lib/simple_form/inputs/date_time_input.rb
|
95
95
|
- lib/simple_form/inputs/file_input.rb
|
96
96
|
- lib/simple_form/inputs/grouped_collection_select_input.rb
|
@@ -99,6 +99,7 @@ files:
|
|
99
99
|
- lib/simple_form/inputs/password_input.rb
|
100
100
|
- lib/simple_form/inputs/priority_input.rb
|
101
101
|
- lib/simple_form/inputs/range_input.rb
|
102
|
+
- lib/simple_form/inputs/rich_text_area_input.rb
|
102
103
|
- lib/simple_form/inputs/string_input.rb
|
103
104
|
- lib/simple_form/inputs/text_input.rb
|
104
105
|
- lib/simple_form/map_type.rb
|
@@ -129,6 +130,7 @@ files:
|
|
129
130
|
- test/inputs/collection_check_boxes_input_test.rb
|
130
131
|
- test/inputs/collection_radio_buttons_input_test.rb
|
131
132
|
- test/inputs/collection_select_input_test.rb
|
133
|
+
- test/inputs/color_input_test.rb
|
132
134
|
- test/inputs/datetime_input_test.rb
|
133
135
|
- test/inputs/disabled_test.rb
|
134
136
|
- test/inputs/discovery_test.rb
|
@@ -140,6 +142,7 @@ files:
|
|
140
142
|
- test/inputs/priority_input_test.rb
|
141
143
|
- test/inputs/readonly_test.rb
|
142
144
|
- test/inputs/required_test.rb
|
145
|
+
- test/inputs/rich_text_area_input_test.rb
|
143
146
|
- test/inputs/string_input_test.rb
|
144
147
|
- test/inputs/text_input_test.rb
|
145
148
|
- test/simple_form_test.rb
|
@@ -148,11 +151,11 @@ files:
|
|
148
151
|
- test/support/mock_controller.rb
|
149
152
|
- test/support/models.rb
|
150
153
|
- test/test_helper.rb
|
151
|
-
homepage: https://github.com/
|
154
|
+
homepage: https://github.com/heartcombo/simple_form
|
152
155
|
licenses:
|
153
156
|
- MIT
|
154
157
|
metadata: {}
|
155
|
-
post_install_message:
|
158
|
+
post_install_message:
|
156
159
|
rdoc_options: []
|
157
160
|
require_paths:
|
158
161
|
- lib
|
@@ -160,53 +163,54 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
160
163
|
requirements:
|
161
164
|
- - ">="
|
162
165
|
- !ruby/object:Gem::Version
|
163
|
-
version:
|
166
|
+
version: 2.5.0
|
164
167
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
165
168
|
requirements:
|
166
169
|
- - ">="
|
167
170
|
- !ruby/object:Gem::Version
|
168
171
|
version: '0'
|
169
172
|
requirements: []
|
170
|
-
|
171
|
-
|
172
|
-
signing_key:
|
173
|
+
rubygems_version: 3.2.6
|
174
|
+
signing_key:
|
173
175
|
specification_version: 4
|
174
176
|
summary: Forms made easy!
|
175
177
|
test_files:
|
176
|
-
- test/action_view_extensions/builder_test.rb
|
177
|
-
- test/action_view_extensions/form_helper_test.rb
|
178
|
-
- test/components/custom_components_test.rb
|
179
178
|
- test/components/label_test.rb
|
180
|
-
- test/
|
181
|
-
- test/
|
182
|
-
- test/
|
179
|
+
- test/components/custom_components_test.rb
|
180
|
+
- test/support/discovery_inputs.rb
|
181
|
+
- test/support/misc_helpers.rb
|
182
|
+
- test/support/mock_controller.rb
|
183
|
+
- test/support/models.rb
|
184
|
+
- test/test_helper.rb
|
183
185
|
- test/form_builder/error_test.rb
|
184
|
-
- test/form_builder/general_test.rb
|
185
186
|
- test/form_builder/hint_test.rb
|
187
|
+
- test/form_builder/error_notification_test.rb
|
188
|
+
- test/form_builder/general_test.rb
|
189
|
+
- test/form_builder/button_test.rb
|
186
190
|
- test/form_builder/input_field_test.rb
|
187
191
|
- test/form_builder/label_test.rb
|
188
192
|
- test/form_builder/wrapper_test.rb
|
193
|
+
- test/form_builder/association_test.rb
|
189
194
|
- test/generators/simple_form_generator_test.rb
|
190
|
-
- test/
|
195
|
+
- test/action_view_extensions/builder_test.rb
|
196
|
+
- test/action_view_extensions/form_helper_test.rb
|
197
|
+
- test/simple_form_test.rb
|
198
|
+
- test/inputs/string_input_test.rb
|
199
|
+
- test/inputs/numeric_input_test.rb
|
200
|
+
- test/inputs/rich_text_area_input_test.rb
|
201
|
+
- test/inputs/readonly_test.rb
|
202
|
+
- test/inputs/grouped_collection_select_input_test.rb
|
203
|
+
- test/inputs/text_input_test.rb
|
191
204
|
- test/inputs/collection_check_boxes_input_test.rb
|
192
|
-
- test/inputs/
|
193
|
-
- test/inputs/collection_select_input_test.rb
|
194
|
-
- test/inputs/datetime_input_test.rb
|
205
|
+
- test/inputs/boolean_input_test.rb
|
195
206
|
- test/inputs/disabled_test.rb
|
196
207
|
- test/inputs/discovery_test.rb
|
197
|
-
- test/inputs/
|
208
|
+
- test/inputs/collection_select_input_test.rb
|
198
209
|
- test/inputs/general_test.rb
|
199
|
-
- test/inputs/
|
200
|
-
- test/inputs/hidden_input_test.rb
|
201
|
-
- test/inputs/numeric_input_test.rb
|
202
|
-
- test/inputs/priority_input_test.rb
|
203
|
-
- test/inputs/readonly_test.rb
|
210
|
+
- test/inputs/color_input_test.rb
|
204
211
|
- test/inputs/required_test.rb
|
205
|
-
- test/inputs/
|
206
|
-
- test/inputs/
|
207
|
-
- test/
|
208
|
-
- test/
|
209
|
-
- test/
|
210
|
-
- test/support/mock_controller.rb
|
211
|
-
- test/support/models.rb
|
212
|
-
- test/test_helper.rb
|
212
|
+
- test/inputs/collection_radio_buttons_input_test.rb
|
213
|
+
- test/inputs/priority_input_test.rb
|
214
|
+
- test/inputs/hidden_input_test.rb
|
215
|
+
- test/inputs/file_input_test.rb
|
216
|
+
- test/inputs/datetime_input_test.rb
|
@@ -1,23 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
module SimpleForm
|
3
|
-
# A lot of configuration values are retrived from I18n,
|
4
|
-
# like boolean collection, required string. This module provides
|
5
|
-
# caching facility to speed up form construction.
|
6
|
-
module I18nCache
|
7
|
-
def i18n_cache(key)
|
8
|
-
get_i18n_cache(key)[I18n.locale] ||= yield.freeze
|
9
|
-
end
|
10
|
-
|
11
|
-
def get_i18n_cache(key)
|
12
|
-
if class_variable_defined?(:"@@#{key}")
|
13
|
-
class_variable_get(:"@@#{key}")
|
14
|
-
else
|
15
|
-
reset_i18n_cache(key)
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
def reset_i18n_cache(key)
|
20
|
-
class_variable_set(:"@@#{key}", {})
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|