simple_form 3.0.0 → 3.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.
Files changed (89) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +44 -22
  3. data/MIT-LICENSE +1 -1
  4. data/README.md +204 -81
  5. data/lib/generators/simple_form/install_generator.rb +3 -3
  6. data/lib/generators/simple_form/templates/README +3 -4
  7. data/lib/generators/simple_form/templates/config/initializers/simple_form.rb +28 -7
  8. data/lib/generators/simple_form/templates/config/initializers/simple_form_bootstrap.rb +115 -24
  9. data/lib/generators/simple_form/templates/config/initializers/simple_form_foundation.rb +86 -5
  10. data/lib/generators/simple_form/templates/config/locales/simple_form.en.yml +7 -2
  11. data/lib/simple_form/action_view_extensions/builder.rb +1 -0
  12. data/lib/simple_form/action_view_extensions/form_helper.rb +6 -2
  13. data/lib/simple_form/components/errors.rb +28 -2
  14. data/lib/simple_form/components/hints.rb +8 -3
  15. data/lib/simple_form/components/html5.rb +1 -1
  16. data/lib/simple_form/components/label_input.rb +20 -2
  17. data/lib/simple_form/components/labels.rb +10 -6
  18. data/lib/simple_form/components/maxlength.rb +1 -1
  19. data/lib/simple_form/components/min_max.rb +1 -1
  20. data/lib/simple_form/components/pattern.rb +1 -1
  21. data/lib/simple_form/components/placeholders.rb +2 -2
  22. data/lib/simple_form/components/readonly.rb +1 -1
  23. data/lib/simple_form/form_builder.rb +123 -73
  24. data/lib/simple_form/helpers.rb +5 -5
  25. data/lib/simple_form/inputs/base.rb +36 -11
  26. data/lib/simple_form/inputs/block_input.rb +1 -1
  27. data/lib/simple_form/inputs/boolean_input.rb +28 -15
  28. data/lib/simple_form/inputs/collection_input.rb +30 -9
  29. data/lib/simple_form/inputs/collection_radio_buttons_input.rb +6 -11
  30. data/lib/simple_form/inputs/collection_select_input.rb +4 -2
  31. data/lib/simple_form/inputs/date_time_input.rb +12 -2
  32. data/lib/simple_form/inputs/file_input.rb +4 -2
  33. data/lib/simple_form/inputs/grouped_collection_select_input.rb +15 -3
  34. data/lib/simple_form/inputs/hidden_input.rb +4 -2
  35. data/lib/simple_form/inputs/numeric_input.rb +5 -4
  36. data/lib/simple_form/inputs/password_input.rb +4 -2
  37. data/lib/simple_form/inputs/priority_input.rb +4 -2
  38. data/lib/simple_form/inputs/range_input.rb +1 -1
  39. data/lib/simple_form/inputs/string_input.rb +4 -2
  40. data/lib/simple_form/inputs/text_input.rb +4 -2
  41. data/lib/simple_form/railtie.rb +7 -0
  42. data/lib/simple_form/tags.rb +6 -0
  43. data/lib/simple_form/version.rb +1 -1
  44. data/lib/simple_form/wrappers/builder.rb +6 -6
  45. data/lib/simple_form/wrappers/leaf.rb +28 -0
  46. data/lib/simple_form/wrappers/many.rb +6 -6
  47. data/lib/simple_form/wrappers/root.rb +1 -1
  48. data/lib/simple_form/wrappers/single.rb +5 -3
  49. data/lib/simple_form/wrappers.rb +1 -0
  50. data/lib/simple_form.rb +59 -8
  51. data/test/action_view_extensions/builder_test.rb +36 -36
  52. data/test/action_view_extensions/form_helper_test.rb +33 -14
  53. data/test/components/label_test.rb +37 -37
  54. data/test/form_builder/association_test.rb +52 -35
  55. data/test/form_builder/button_test.rb +10 -10
  56. data/test/form_builder/error_notification_test.rb +1 -1
  57. data/test/form_builder/error_test.rb +147 -22
  58. data/test/form_builder/general_test.rb +89 -64
  59. data/test/form_builder/hint_test.rb +23 -17
  60. data/test/form_builder/input_field_test.rb +80 -16
  61. data/test/form_builder/label_test.rb +52 -10
  62. data/test/form_builder/wrapper_test.rb +135 -19
  63. data/test/generators/simple_form_generator_test.rb +4 -4
  64. data/test/inputs/boolean_input_test.rb +62 -6
  65. data/test/inputs/collection_check_boxes_input_test.rb +85 -17
  66. data/test/inputs/collection_radio_buttons_input_test.rb +134 -36
  67. data/test/inputs/collection_select_input_test.rb +146 -41
  68. data/test/inputs/datetime_input_test.rb +117 -50
  69. data/test/inputs/disabled_test.rb +15 -15
  70. data/test/inputs/discovery_test.rb +56 -6
  71. data/test/inputs/file_input_test.rb +2 -2
  72. data/test/inputs/general_test.rb +20 -20
  73. data/test/inputs/grouped_collection_select_input_test.rb +44 -8
  74. data/test/inputs/hidden_input_test.rb +4 -4
  75. data/test/inputs/numeric_input_test.rb +43 -43
  76. data/test/inputs/priority_input_test.rb +13 -13
  77. data/test/inputs/readonly_test.rb +19 -19
  78. data/test/inputs/required_test.rb +13 -13
  79. data/test/inputs/string_input_test.rb +50 -30
  80. data/test/inputs/text_input_test.rb +7 -7
  81. data/test/simple_form_test.rb +8 -0
  82. data/test/support/discovery_inputs.rb +32 -2
  83. data/test/support/misc_helpers.rb +77 -5
  84. data/test/support/models.rb +60 -24
  85. data/test/test_helper.rb +7 -1
  86. metadata +22 -36
  87. data/lib/simple_form/action_view_extensions/builder.rb.orig +0 -247
  88. data/lib/simple_form/form_builder.rb.orig +0 -486
  89. data/lib/simple_form/version.rb.orig +0 -7
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.0
4
+ version: 3.1.0
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: 2013-09-21 00:00:00.000000000 Z
13
+ date: 2014-11-25 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.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.1'
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.1'
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.0
52
- - - <
53
- - !ruby/object:Gem::Version
54
- version: '4.1'
42
+ version: '4.0'
55
43
  description: Forms made easy!
56
- email: contact@plataformatec.com.br
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,11 +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/generators/simple_form/templates/README
73
- - lib/generators/simple_form/USAGE
62
+ - lib/simple_form.rb
74
63
  - lib/simple_form/action_view_extensions/builder.rb
75
- - lib/simple_form/action_view_extensions/builder.rb.orig
76
64
  - lib/simple_form/action_view_extensions/form_helper.rb
65
+ - lib/simple_form/components.rb
77
66
  - lib/simple_form/components/errors.rb
78
67
  - lib/simple_form/components/hints.rb
79
68
  - lib/simple_form/components/html5.rb
@@ -84,17 +73,16 @@ files:
84
73
  - lib/simple_form/components/pattern.rb
85
74
  - lib/simple_form/components/placeholders.rb
86
75
  - lib/simple_form/components/readonly.rb
87
- - lib/simple_form/components.rb
88
76
  - lib/simple_form/error_notification.rb
89
77
  - lib/simple_form/form_builder.rb
90
- - lib/simple_form/form_builder.rb.orig
78
+ - lib/simple_form/helpers.rb
91
79
  - lib/simple_form/helpers/autofocus.rb
92
80
  - lib/simple_form/helpers/disabled.rb
93
81
  - lib/simple_form/helpers/readonly.rb
94
82
  - lib/simple_form/helpers/required.rb
95
83
  - lib/simple_form/helpers/validators.rb
96
- - lib/simple_form/helpers.rb
97
84
  - lib/simple_form/i18n_cache.rb
85
+ - lib/simple_form/inputs.rb
98
86
  - lib/simple_form/inputs/base.rb
99
87
  - lib/simple_form/inputs/block_input.rb
100
88
  - lib/simple_form/inputs/boolean_input.rb
@@ -112,18 +100,16 @@ files:
112
100
  - lib/simple_form/inputs/range_input.rb
113
101
  - lib/simple_form/inputs/string_input.rb
114
102
  - lib/simple_form/inputs/text_input.rb
115
- - lib/simple_form/inputs.rb
116
103
  - lib/simple_form/map_type.rb
117
104
  - lib/simple_form/railtie.rb
118
105
  - lib/simple_form/tags.rb
119
106
  - lib/simple_form/version.rb
120
- - lib/simple_form/version.rb.orig
107
+ - lib/simple_form/wrappers.rb
121
108
  - lib/simple_form/wrappers/builder.rb
109
+ - lib/simple_form/wrappers/leaf.rb
122
110
  - lib/simple_form/wrappers/many.rb
123
111
  - lib/simple_form/wrappers/root.rb
124
112
  - lib/simple_form/wrappers/single.rb
125
- - lib/simple_form/wrappers.rb
126
- - lib/simple_form.rb
127
113
  - test/action_view_extensions/builder_test.rb
128
114
  - test/action_view_extensions/form_helper_test.rb
129
115
  - test/components/label_test.rb
@@ -170,17 +156,17 @@ require_paths:
170
156
  - lib
171
157
  required_ruby_version: !ruby/object:Gem::Requirement
172
158
  requirements:
173
- - - '>='
159
+ - - ">="
174
160
  - !ruby/object:Gem::Version
175
161
  version: '0'
176
162
  required_rubygems_version: !ruby/object:Gem::Requirement
177
163
  requirements:
178
- - - '>='
164
+ - - ">="
179
165
  - !ruby/object:Gem::Version
180
166
  version: '0'
181
167
  requirements: []
182
168
  rubyforge_project: simple_form
183
- rubygems_version: 2.0.6
169
+ rubygems_version: 2.2.2
184
170
  signing_key:
185
171
  specification_version: 4
186
172
  summary: Forms made easy!
@@ -1,247 +0,0 @@
1
- module SimpleForm
2
- module ActionViewExtensions
3
- # A collection of methods required by simple_form but added to rails default form.
4
- # This means that you can use such methods outside simple_form context.
5
- module Builder
6
-
7
- # Wrapper for using SimpleForm inside a default rails form.
8
- # Example:
9
- #
10
- # form_for @user do |f|
11
- # f.simple_fields_for :posts do |posts_form|
12
- # # Here you have all simple_form methods available
13
- # posts_form.input :title
14
- # end
15
- # end
16
- def simple_fields_for(*args, &block)
17
- options = args.extract_options!
18
- options[:wrapper] = self.options[:wrapper] if options[:wrapper].nil?
19
- options[:defaults] ||= self.options[:defaults]
20
-
21
- if self.class < ActionView::Helpers::FormBuilder
22
- options[:builder] ||= self.class
23
- else
24
- options[:builder] ||= SimpleForm::FormBuilder
25
- end
26
- fields_for(*(args << options), &block)
27
- end
28
- end
29
- end
30
- end
31
-
32
- module SimpleForm
33
- module Tags
34
- module CollectionExtensions
35
- private
36
-
37
- def render_collection
38
- item_wrapper_tag = @options.fetch(:item_wrapper_tag, :span)
39
- item_wrapper_class = @options[:item_wrapper_class]
40
-
41
- @collection.map do |item|
42
- value = value_for_collection(item, @value_method)
43
- text = value_for_collection(item, @text_method)
44
- default_html_options = default_html_options_for_collection(item, value)
45
-
46
- rendered_item = yield item, value, text, default_html_options
47
-
48
- item_wrapper_tag ? @template_object.content_tag(item_wrapper_tag, rendered_item, :class => item_wrapper_class) : rendered_item
49
- end.join.html_safe
50
- end
51
-
52
- def wrap_rendered_collection(collection)
53
- wrapper_tag = @options[:collection_wrapper_tag]
54
-
55
- if wrapper_tag
56
- wrapper_class = @options[:collection_wrapper_class]
57
- @template_object.content_tag(wrapper_tag, collection, :class => wrapper_class)
58
- else
59
- collection
60
- end
61
- end
62
- end
63
-
64
- class CollectionRadioButtons < ActionView::Helpers::Tags::CollectionRadioButtons
65
- include CollectionExtensions
66
-
67
- def render
68
- wrap_rendered_collection(super)
69
- end
70
-
71
- private
72
-
73
- def render_component(builder)
74
- builder.radio_button + builder.label(:class => "collection_radio_buttons")
75
- end
76
- end
77
-
78
- class CollectionCheckBoxes < ActionView::Helpers::Tags::CollectionCheckBoxes
79
- include CollectionExtensions
80
-
81
- def render
82
- wrap_rendered_collection(super)
83
- end
84
-
85
- private
86
-
87
- def render_component(builder)
88
- builder.check_box + builder.label(:class => "collection_check_boxes")
89
- end
90
- end
91
- end
92
- end
93
-
94
- module ActionView::Helpers
95
- class FormBuilder
96
- include SimpleForm::ActionViewExtensions::Builder
97
- end
98
-
99
- <<<<<<< HEAD
100
- # Create a collection of radio inputs for the attribute. Basically this
101
- # helper will create a radio input associated with a label for each
102
- # text/value option in the collection, using value_method and text_method
103
- # to convert these text/value. You can give a symbol or a proc to both
104
- # value_method and text_method, that will be evaluated for each item in
105
- # the collection.
106
- #
107
- # == Examples
108
- #
109
- # form_for @user do |f|
110
- # f.collection_radio_buttons :options, [[true, 'Yes'] ,[false, 'No']], :first, :last
111
- # end
112
- #
113
- # <input id="user_options_true" name="user[options]" type="radio" value="true" />
114
- # <label class="collection_radio_buttons" for="user_options_true">Yes</label>
115
- # <input id="user_options_false" name="user[options]" type="radio" value="false" />
116
- # <label class="collection_radio_buttons" for="user_options_false">No</label>
117
- #
118
- # It is also possible to give a block that should generate the radio +
119
- # label. To wrap the radio with the label, for instance:
120
- #
121
- # form_for @user do |f|
122
- # f.collection_radio_buttons(
123
- # :options, [[true, 'Yes'] ,[false, 'No']], :first, :last
124
- # ) do |b|
125
- # b.label { b.radio_button + b.text }
126
- # end
127
- # end
128
- #
129
- # == Options
130
- #
131
- # Collection radio accepts some extra options:
132
- #
133
- # * checked => the value that should be checked initially.
134
- #
135
- # * disabled => the value or values that should be disabled. Accepts a single
136
- # item or an array of items.
137
- #
138
- # * collection_wrapper_tag => the tag to wrap the entire collection.
139
- #
140
- # * collection_wrapper_class => the CSS class to use for collection_wrapper_tag
141
- #
142
- # * item_wrapper_tag => the tag to wrap each item in the collection.
143
- #
144
- # * item_wrapper_class => the CSS class to use for item_wrapper_tag
145
- #
146
- # * a block => to generate the label + radio or any other component.
147
- def collection_radio_buttons(method, collection, value_method, text_method, options = {}, html_options = {}, &block)
148
- SimpleForm::Tags::CollectionRadioButtons.new(@object_name, method, @template, collection, value_method, text_method, objectify_options(options), @default_options.merge(html_options)).render(&block)
149
- =======
150
- module FormOptionsHelper
151
- # Override Rails options_from_collection_for_select to handle lambdas/procs in
152
- # text and value methods, so it works the same way as collection_radio_buttons
153
- # and collection_check_boxes in SimpleForm. If none of text/value methods is a
154
- # callable object, then it just delegates back to original collection select.
155
- # FIXME: remove when support only Rails 4.0 forward
156
- # https://github.com/rails/rails/commit/9035324367526af0300477a58b6d3efc15d1a5a8
157
- alias :original_options_from_collection_for_select :options_from_collection_for_select
158
- def options_from_collection_for_select(collection, value_method, text_method, selected = nil)
159
- if value_method.respond_to?(:call) || text_method.respond_to?(:call)
160
- collection = collection.map do |item|
161
- value = value_for_collection(item, value_method)
162
- text = value_for_collection(item, text_method)
163
-
164
- [value, text]
165
- end
166
-
167
- value_method, text_method = :first, :last
168
- selected = extract_selected_and_disabled_and_call_procs selected, collection
169
- end
170
-
171
- original_options_from_collection_for_select collection, value_method, text_method, selected
172
- end
173
-
174
- private
175
-
176
- def extract_selected_and_disabled_and_call_procs(selected, collection)
177
- selected, disabled = extract_selected_and_disabled selected
178
- selected_disabled = { :selected => selected, :disabled => disabled }
179
-
180
- selected_disabled.each do |key, check|
181
- if check.is_a? Proc
182
- values = collection.map { |option| option.first if check.call(option.first) }
183
- selected_disabled[key] = values
184
- end
185
- end
186
- end
187
-
188
- def value_for_collection(item, value) #:nodoc:
189
- value.respond_to?(:call) ? value.call(item) : item.send(value)
190
- >>>>>>> master
191
- end
192
-
193
- # Creates a collection of check boxes for each item in the collection,
194
- # associated with a clickable label. Use value_method and text_method to
195
- # convert items in the collection for use as text/value in check boxes.
196
- # You can give a symbol or a proc to both value_method and text_method,
197
- # that will be evaluated for each item in the collection.
198
- #
199
- # == Examples
200
- #
201
- # form_for @user do |f|
202
- # f.collection_check_boxes :options, [[true, 'Yes'] ,[false, 'No']], :first, :last
203
- # end
204
- #
205
- # <input name="user[options][]" type="hidden" value="" />
206
- # <input id="user_options_true" name="user[options][]" type="checkbox" value="true" />
207
- # <label class="collection_check_boxes" for="user_options_true">Yes</label>
208
- # <input name="user[options][]" type="hidden" value="" />
209
- # <input id="user_options_false" name="user[options][]" type="checkbox" value="false" />
210
- # <label class="collection_check_boxes" for="user_options_false">No</label>
211
- #
212
- # It is also possible to give a block that should generate the check box +
213
- # label. To wrap the check box with the label, for instance:
214
- #
215
- # form_for @user do |f|
216
- # f.collection_check_boxes(
217
- # :options, [[true, 'Yes'] ,[false, 'No']], :first, :last
218
- # ) do |b|
219
- # b.label { b.check_box + b.text }
220
- # end
221
- # end
222
- #
223
- # == Options
224
- #
225
- # Collection check box accepts some extra options:
226
- #
227
- # * checked => the value or values that should be checked initially. Accepts
228
- # a single item or an array of items. It overrides existing associations.
229
- #
230
- # * disabled => the value or values that should be disabled. Accepts a single
231
- # item or an array of items.
232
- #
233
- # * collection_wrapper_tag => the tag to wrap the entire collection.
234
- #
235
- # * collection_wrapper_class => the CSS class to use for collection_wrapper_tag. This option
236
- # is ignored if the :collection_wrapper_tag option is blank.
237
- #
238
- # * item_wrapper_tag => the tag to wrap each item in the collection.
239
- #
240
- # * item_wrapper_class => the CSS class to use for item_wrapper_tag
241
- #
242
- # * a block => to generate the label + check box or any other component.
243
- def collection_check_boxes(method, collection, value_method, text_method, options = {}, html_options = {}, &block)
244
- SimpleForm::Tags::CollectionCheckBoxes.new(@object_name, method, @template, collection, value_method, text_method, objectify_options(options), @default_options.merge(html_options)).render(&block)
245
- end
246
- end
247
- end