simple_form 2.1.0 → 3.2.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.
Potentially problematic release.
This version of simple_form might be problematic. Click here for more details.
- checksums.yaml +7 -0
- data/CHANGELOG.md +77 -33
- data/MIT-LICENSE +1 -1
- data/README.md +387 -187
- data/lib/generators/simple_form/install_generator.rb +4 -4
- data/lib/generators/simple_form/templates/README +3 -4
- data/lib/generators/simple_form/templates/config/initializers/simple_form.rb +45 -22
- data/lib/generators/simple_form/templates/config/initializers/simple_form_bootstrap.rb +128 -24
- data/lib/generators/simple_form/templates/config/initializers/simple_form_foundation.rb +87 -6
- data/lib/generators/simple_form/templates/config/locales/simple_form.en.yml +7 -2
- data/lib/simple_form/action_view_extensions/builder.rb +2 -319
- data/lib/simple_form/action_view_extensions/form_helper.rb +8 -11
- data/lib/simple_form/components/errors.rb +28 -2
- data/lib/simple_form/components/hints.rb +8 -3
- data/lib/simple_form/components/html5.rb +6 -3
- data/lib/simple_form/components/label_input.rb +20 -2
- data/lib/simple_form/components/labels.rb +14 -10
- data/lib/simple_form/components/maxlength.rb +2 -9
- data/lib/simple_form/components/min_max.rb +1 -1
- data/lib/simple_form/components/pattern.rb +3 -3
- data/lib/simple_form/components/placeholders.rb +2 -2
- data/lib/simple_form/components/readonly.rb +1 -1
- data/lib/simple_form/components.rb +1 -1
- data/lib/simple_form/error_notification.rb +2 -2
- data/lib/simple_form/form_builder.rb +262 -107
- data/lib/simple_form/helpers.rb +6 -6
- data/lib/simple_form/inputs/base.rb +37 -16
- data/lib/simple_form/inputs/block_input.rb +2 -2
- data/lib/simple_form/inputs/boolean_input.rb +33 -18
- data/lib/simple_form/inputs/collection_input.rb +34 -13
- data/lib/simple_form/inputs/collection_radio_buttons_input.rb +7 -12
- data/lib/simple_form/inputs/collection_select_input.rb +4 -2
- data/lib/simple_form/inputs/date_time_input.rb +23 -9
- 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 +3 -8
- data/lib/simple_form/inputs/password_input.rb +4 -3
- 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 -3
- data/lib/simple_form/inputs/text_input.rb +4 -2
- data/lib/simple_form/railtie.rb +14 -0
- data/lib/simple_form/tags.rb +68 -0
- data/lib/simple_form/version.rb +1 -1
- data/lib/simple_form/wrappers/builder.rb +11 -35
- data/lib/simple_form/wrappers/leaf.rb +28 -0
- data/lib/simple_form/wrappers/many.rb +7 -7
- data/lib/simple_form/wrappers/root.rb +2 -2
- data/lib/simple_form/wrappers/single.rb +5 -3
- data/lib/simple_form/wrappers.rb +2 -1
- data/lib/simple_form.rb +99 -52
- data/test/action_view_extensions/builder_test.rb +113 -127
- data/test/action_view_extensions/form_helper_test.rb +58 -30
- data/test/components/label_test.rb +83 -83
- data/test/form_builder/association_test.rb +96 -61
- data/test/form_builder/button_test.rb +14 -14
- data/test/form_builder/error_notification_test.rb +9 -9
- data/test/form_builder/error_test.rb +159 -34
- data/test/form_builder/general_test.rb +176 -121
- data/test/form_builder/hint_test.rb +43 -37
- data/test/form_builder/input_field_test.rb +99 -52
- data/test/form_builder/label_test.rb +67 -15
- data/test/form_builder/wrapper_test.rb +157 -41
- data/test/generators/simple_form_generator_test.rb +4 -4
- data/test/inputs/boolean_input_test.rb +92 -24
- data/test/inputs/collection_check_boxes_input_test.rb +150 -71
- data/test/inputs/collection_radio_buttons_input_test.rb +213 -113
- data/test/inputs/collection_select_input_test.rb +221 -85
- data/test/inputs/datetime_input_test.rb +125 -47
- data/test/inputs/disabled_test.rb +25 -25
- data/test/inputs/discovery_test.rb +60 -10
- data/test/inputs/file_input_test.rb +3 -3
- data/test/inputs/general_test.rb +48 -32
- data/test/inputs/grouped_collection_select_input_test.rb +76 -27
- data/test/inputs/hidden_input_test.rb +6 -5
- data/test/inputs/numeric_input_test.rb +46 -46
- data/test/inputs/priority_input_test.rb +21 -15
- data/test/inputs/readonly_test.rb +31 -31
- data/test/inputs/required_test.rb +30 -18
- data/test/inputs/string_input_test.rb +53 -52
- data/test/inputs/text_input_test.rb +15 -8
- data/test/simple_form_test.rb +8 -0
- data/test/support/discovery_inputs.rb +32 -2
- data/test/support/misc_helpers.rb +130 -29
- data/test/support/mock_controller.rb +6 -6
- data/test/support/models.rb +125 -71
- data/test/test_helper.rb +28 -35
- metadata +17 -29
- data/lib/simple_form/action_view_extensions/builder.rb.orig +0 -247
- data/lib/simple_form/core_ext/hash.rb +0 -16
- data/lib/simple_form/form_builder.rb.orig +0 -486
- data/lib/simple_form/version.rb.orig +0 -7
data/lib/simple_form/version.rb
CHANGED
@@ -12,18 +12,18 @@ module SimpleForm
|
|
12
12
|
# b.optional :placeholder
|
13
13
|
#
|
14
14
|
# # Use a component with specific wrapper options
|
15
|
-
# b.use :error, :
|
15
|
+
# b.use :error, wrap_with: { tag: "span", class: "error" }
|
16
16
|
#
|
17
17
|
# # Use a set of components by wrapping them in a tag+class.
|
18
|
-
# b.wrapper :
|
18
|
+
# b.wrapper tag: "div", class: "another" do |ba|
|
19
19
|
# ba.use :label
|
20
20
|
# ba.use :input
|
21
21
|
# end
|
22
22
|
#
|
23
23
|
# # Use a set of components by wrapping them in a tag+class.
|
24
24
|
# # This wrapper is identified by :label_input, which means it can
|
25
|
-
# # be turned off on demand with `f.input :name, :
|
26
|
-
# b.wrapper :label_input, :
|
25
|
+
# # be turned off on demand with `f.input :name, label_input: false`
|
26
|
+
# b.wrapper :label_input, tag: "div", class: "another" do |ba|
|
27
27
|
# ba.use :label
|
28
28
|
# ba.use :input
|
29
29
|
# end
|
@@ -32,7 +32,7 @@ module SimpleForm
|
|
32
32
|
# The builder also accepts default options at the root level. This is usually
|
33
33
|
# used if you want a component to be disabled by default:
|
34
34
|
#
|
35
|
-
# config.wrappers :
|
35
|
+
# config.wrappers hint: false do |b|
|
36
36
|
# b.use :hint
|
37
37
|
# b.use :label_input
|
38
38
|
# end
|
@@ -45,44 +45,20 @@ module SimpleForm
|
|
45
45
|
@components = []
|
46
46
|
end
|
47
47
|
|
48
|
-
def use(name, options=
|
49
|
-
if block_given?
|
50
|
-
ActiveSupport::Deprecation.warn "Passing a block to use is deprecated. " \
|
51
|
-
"Please use wrapper instead of use."
|
52
|
-
return wrapper(name, options, &block)
|
53
|
-
end
|
54
|
-
|
55
|
-
if options && options.keys != [:wrap_with]
|
56
|
-
ActiveSupport::Deprecation.warn "Passing :tag, :class and others to use is deprecated. " \
|
57
|
-
"Please invoke b.use #{name.inspect}, :wrap_with => #{options.inspect} instead."
|
58
|
-
options = { :wrap_with => options }
|
59
|
-
end
|
60
|
-
|
48
|
+
def use(name, options = {})
|
61
49
|
if options && wrapper = options[:wrap_with]
|
62
|
-
@components << Single.new(name, wrapper)
|
50
|
+
@components << Single.new(name, wrapper, options.except(:wrap_with))
|
63
51
|
else
|
64
|
-
@components << name
|
52
|
+
@components << Leaf.new(name, options)
|
65
53
|
end
|
66
54
|
end
|
67
55
|
|
68
|
-
def optional(name, options=
|
69
|
-
if block_given?
|
70
|
-
ActiveSupport::Deprecation.warn "Passing a block to optional is deprecated. " \
|
71
|
-
"Please use wrapper instead of optional."
|
72
|
-
return wrapper(name, options, &block)
|
73
|
-
end
|
74
|
-
|
75
|
-
if options && options.keys != [:wrap_with]
|
76
|
-
ActiveSupport::Deprecation.warn "Passing :tag, :class and others to optional is deprecated. " \
|
77
|
-
"Please invoke b.optional #{name.inspect}, :wrap_with => #{options.inspect} instead."
|
78
|
-
options = { :wrap_with => options }
|
79
|
-
end
|
80
|
-
|
56
|
+
def optional(name, options = {}, &block)
|
81
57
|
@options[name] = false
|
82
|
-
use(name, options
|
58
|
+
use(name, options)
|
83
59
|
end
|
84
60
|
|
85
|
-
def wrapper(name, options=nil)
|
61
|
+
def wrapper(name, options = nil)
|
86
62
|
if block_given?
|
87
63
|
name, options = nil, name if name.is_a?(Hash)
|
88
64
|
builder = self.class.new(@options)
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module SimpleForm
|
2
|
+
module Wrappers
|
3
|
+
class Leaf
|
4
|
+
attr_reader :namespace
|
5
|
+
|
6
|
+
def initialize(namespace, options = {})
|
7
|
+
@namespace = namespace
|
8
|
+
@options = options
|
9
|
+
end
|
10
|
+
|
11
|
+
def render(input)
|
12
|
+
method = input.method(@namespace)
|
13
|
+
|
14
|
+
if method.arity == 0
|
15
|
+
ActiveSupport::Deprecation.warn(SimpleForm::CUSTOM_INPUT_DEPRECATION_WARN % { name: @namespace })
|
16
|
+
|
17
|
+
method.call
|
18
|
+
else
|
19
|
+
method.call(@options)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def find(name)
|
24
|
+
self if @namespace == name
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
module SimpleForm
|
2
2
|
module Wrappers
|
3
3
|
# A wrapper is an object that holds several components and render them.
|
4
|
-
# A component may
|
4
|
+
# A component may be any object that responds to `render`.
|
5
5
|
# This API allows inputs/components to be easily wrapped, removing the
|
6
6
|
# need to modify the code only to wrap input in an extra tag.
|
7
7
|
#
|
@@ -10,14 +10,13 @@ module SimpleForm
|
|
10
10
|
# on demand on input generation.
|
11
11
|
class Many
|
12
12
|
attr_reader :namespace, :defaults, :components
|
13
|
-
alias :to_sym :namespace
|
14
13
|
|
15
|
-
def initialize(namespace, components, defaults={})
|
14
|
+
def initialize(namespace, components, defaults = {})
|
16
15
|
@namespace = namespace
|
17
16
|
@components = components
|
18
17
|
@defaults = defaults
|
19
18
|
@defaults[:tag] = :div unless @defaults.key?(:tag)
|
20
|
-
@defaults[:class] = Array
|
19
|
+
@defaults[:class] = Array(@defaults[:class])
|
21
20
|
end
|
22
21
|
|
23
22
|
def render(input)
|
@@ -25,8 +24,8 @@ module SimpleForm
|
|
25
24
|
options = input.options
|
26
25
|
|
27
26
|
components.each do |component|
|
28
|
-
next if options[component] == false
|
29
|
-
rendered = component.
|
27
|
+
next if options[component.namespace] == false
|
28
|
+
rendered = component.render(input)
|
30
29
|
content.safe_concat rendered.to_s if rendered
|
31
30
|
end
|
32
31
|
|
@@ -51,6 +50,7 @@ module SimpleForm
|
|
51
50
|
|
52
51
|
def wrap(input, options, content)
|
53
52
|
return content if options[namespace] == false
|
53
|
+
return if defaults[:unless_blank] && content.empty?
|
54
54
|
|
55
55
|
tag = (namespace && options[:"#{namespace}_tag"]) || @defaults[:tag]
|
56
56
|
return content unless tag
|
@@ -62,7 +62,7 @@ module SimpleForm
|
|
62
62
|
end
|
63
63
|
|
64
64
|
def html_options(options)
|
65
|
-
options[:"#{namespace}_html"] || {}
|
65
|
+
(@defaults[:html] || {}).merge(options[:"#{namespace}_html"] || {})
|
66
66
|
end
|
67
67
|
|
68
68
|
def html_classes(input, options)
|
@@ -17,13 +17,13 @@ module SimpleForm
|
|
17
17
|
|
18
18
|
# Provide a fallback if name cannot be found.
|
19
19
|
def find(name)
|
20
|
-
super || SimpleForm::Wrappers::Many.new(name, [name])
|
20
|
+
super || SimpleForm::Wrappers::Many.new(name, [Leaf.new(name)])
|
21
21
|
end
|
22
22
|
|
23
23
|
private
|
24
24
|
|
25
25
|
def html_classes(input, options)
|
26
|
-
css = options[:wrapper_class] ? Array
|
26
|
+
css = options[:wrapper_class] ? Array(options[:wrapper_class]) : @defaults[:class]
|
27
27
|
css += SimpleForm.additional_classes_for(:wrapper) do
|
28
28
|
input.additional_classes + [input.input_class]
|
29
29
|
end
|
@@ -2,14 +2,16 @@ module SimpleForm
|
|
2
2
|
module Wrappers
|
3
3
|
# `Single` is an optimization for a wrapper that has only one component.
|
4
4
|
class Single < Many
|
5
|
-
def initialize(name, options={})
|
6
|
-
|
5
|
+
def initialize(name, wrapper_options = {}, options = {})
|
6
|
+
@component = Leaf.new(name, options)
|
7
|
+
|
8
|
+
super(name, [@component], wrapper_options)
|
7
9
|
end
|
8
10
|
|
9
11
|
def render(input)
|
10
12
|
options = input.options
|
11
13
|
if options[namespace] != false
|
12
|
-
content =
|
14
|
+
content = @component.render(input)
|
13
15
|
wrap(input, options, content) if content
|
14
16
|
end
|
15
17
|
end
|
data/lib/simple_form/wrappers.rb
CHANGED
data/lib/simple_form.rb
CHANGED
@@ -18,6 +18,30 @@ module SimpleForm
|
|
18
18
|
autoload :Inputs
|
19
19
|
end
|
20
20
|
|
21
|
+
def self.eager_load!
|
22
|
+
super
|
23
|
+
SimpleForm::Inputs.eager_load!
|
24
|
+
SimpleForm::Components.eager_load!
|
25
|
+
end
|
26
|
+
|
27
|
+
CUSTOM_INPUT_DEPRECATION_WARN = <<-WARN
|
28
|
+
%{name} method now accepts a `wrapper_options` argument. The method definition without the argument is deprecated and will be removed in the next Simple Form version. Change your code from:
|
29
|
+
|
30
|
+
def %{name}
|
31
|
+
|
32
|
+
to
|
33
|
+
|
34
|
+
def %{name}(wrapper_options)
|
35
|
+
|
36
|
+
See https://github.com/plataformatec/simple_form/pull/997 for more information.
|
37
|
+
WARN
|
38
|
+
|
39
|
+
@@configured = false
|
40
|
+
|
41
|
+
def self.configured? #:nodoc:
|
42
|
+
@@configured
|
43
|
+
end
|
44
|
+
|
21
45
|
## CONFIGURATION OPTIONS
|
22
46
|
|
23
47
|
# Method used to tidy up errors.
|
@@ -34,11 +58,11 @@ module SimpleForm
|
|
34
58
|
|
35
59
|
# Series of attemps to detect a default label method for collection.
|
36
60
|
mattr_accessor :collection_label_methods
|
37
|
-
@@collection_label_methods = [
|
61
|
+
@@collection_label_methods = [:to_label, :name, :title, :to_s]
|
38
62
|
|
39
63
|
# Series of attemps to detect a default value method for collection.
|
40
64
|
mattr_accessor :collection_value_methods
|
41
|
-
@@collection_value_methods = [
|
65
|
+
@@collection_value_methods = [:id, :to_s]
|
42
66
|
|
43
67
|
# You can wrap a collection of radio/check boxes in a pre-defined tag, defaulting to none.
|
44
68
|
mattr_accessor :collection_wrapper_tag
|
@@ -49,7 +73,7 @@ module SimpleForm
|
|
49
73
|
@@collection_wrapper_class = nil
|
50
74
|
|
51
75
|
# You can wrap each item in a collection of radio/check boxes with a tag,
|
52
|
-
# defaulting to
|
76
|
+
# defaulting to span. Please note that when using :boolean_style = :nested,
|
53
77
|
# SimpleForm will force this option to be a :label.
|
54
78
|
mattr_accessor :item_wrapper_tag
|
55
79
|
@@item_wrapper_tag = :span
|
@@ -60,27 +84,33 @@ module SimpleForm
|
|
60
84
|
|
61
85
|
# How the label text should be generated altogether with the required text.
|
62
86
|
mattr_accessor :label_text
|
63
|
-
@@label_text = lambda { |label, required| "#{required} #{label}" }
|
87
|
+
@@label_text = lambda { |label, required, explicit_label| "#{required} #{label}" }
|
64
88
|
|
65
|
-
# You can define the class to
|
89
|
+
# You can define the class to be used on all labels. Defaults to none.
|
66
90
|
mattr_accessor :label_class
|
67
91
|
@@label_class = nil
|
68
92
|
|
69
93
|
# Define the way to render check boxes / radio buttons with labels.
|
70
|
-
# :
|
71
|
-
# :
|
94
|
+
# inline: input + label (default)
|
95
|
+
# nested: label > input
|
72
96
|
mattr_accessor :boolean_style
|
73
97
|
@@boolean_style = :inline
|
74
98
|
|
75
|
-
# You can define the class to
|
76
|
-
|
99
|
+
# DEPRECATED: You can define the class to be used on all forms. Default is
|
100
|
+
# simple_form.
|
101
|
+
mattr_reader :form_class
|
77
102
|
@@form_class = :simple_form
|
78
103
|
|
79
|
-
# You can define
|
104
|
+
# You can define the default class to be used on all forms. Can be overriden
|
105
|
+
# with `html: { :class }`. Defaults to none.
|
106
|
+
mattr_accessor :default_form_class
|
107
|
+
@@default_form_class = nil
|
108
|
+
|
109
|
+
# You can define which elements should obtain additional classes.
|
80
110
|
mattr_accessor :generate_additional_classes_for
|
81
111
|
@@generate_additional_classes_for = [:wrapper, :label, :input]
|
82
112
|
|
83
|
-
# Whether attributes are required by default
|
113
|
+
# Whether attributes are required by default or not.
|
84
114
|
mattr_accessor :required_by_default
|
85
115
|
@@required_by_default = true
|
86
116
|
|
@@ -90,7 +120,7 @@ module SimpleForm
|
|
90
120
|
|
91
121
|
# Collection of methods to detect if a file type was given.
|
92
122
|
mattr_accessor :file_methods
|
93
|
-
@@file_methods = [
|
123
|
+
@@file_methods = [:mounted_as, :file?, :public_filename]
|
94
124
|
|
95
125
|
# Custom mappings for input types. This should be a hash containing a regexp
|
96
126
|
# to match as key, and the input type that will be used when the field name
|
@@ -100,10 +130,20 @@ module SimpleForm
|
|
100
130
|
|
101
131
|
# Custom wrappers for input types. This should be a hash containing an input
|
102
132
|
# type as key and the wrapper that will be used for all inputs with specified type.
|
103
|
-
# e.g { :
|
133
|
+
# e.g { string: :string_wrapper, boolean: :boolean_wrapper }
|
134
|
+
# You can also set a wrapper mapping per form basis.
|
135
|
+
# e.g simple_form_for(@foo, wrapper_mappings: { check_boxes: :bootstrap_checkbox })
|
104
136
|
mattr_accessor :wrapper_mappings
|
105
137
|
@@wrapper_mappings = nil
|
106
138
|
|
139
|
+
# Namespaces where SimpleForm should look for custom input classes that override
|
140
|
+
# default inputs. Namespaces are given as string to allow lazy loading inputs.
|
141
|
+
# e.g. config.custom_inputs_namespaces << "CustomInputs"
|
142
|
+
# will try to find CustomInputs::NumericInput when an :integer
|
143
|
+
# field is called.
|
144
|
+
mattr_accessor :custom_inputs_namespaces
|
145
|
+
@@custom_inputs_namespaces = []
|
146
|
+
|
107
147
|
# Default priority for time_zone inputs.
|
108
148
|
mattr_accessor :time_zone_priority
|
109
149
|
@@time_zone_priority = nil
|
@@ -112,9 +152,9 @@ module SimpleForm
|
|
112
152
|
mattr_accessor :country_priority
|
113
153
|
@@country_priority = nil
|
114
154
|
|
115
|
-
# Maximum size allowed for inputs.
|
155
|
+
# DEPRECATED: Maximum size allowed for inputs.
|
116
156
|
mattr_accessor :default_input_size
|
117
|
-
@@default_input_size =
|
157
|
+
@@default_input_size = nil
|
118
158
|
|
119
159
|
# When off, do not use translations in labels. Disabling translation in
|
120
160
|
# hints and placeholders can be done manually in the wrapper API.
|
@@ -125,23 +165,46 @@ module SimpleForm
|
|
125
165
|
mattr_accessor :inputs_discovery
|
126
166
|
@@inputs_discovery = true
|
127
167
|
|
128
|
-
# Cache SimpleForm inputs discovery
|
168
|
+
# Cache SimpleForm inputs discovery.
|
129
169
|
mattr_accessor :cache_discovery
|
130
170
|
@@cache_discovery = defined?(Rails) && !Rails.env.development?
|
131
171
|
|
132
|
-
# Adds a class to each generated button, mostly for compatiblity
|
172
|
+
# Adds a class to each generated button, mostly for compatiblity.
|
133
173
|
mattr_accessor :button_class
|
134
174
|
@@button_class = 'button'
|
135
175
|
|
176
|
+
# Override the default ActiveModelHelper behaviour of wrapping the input.
|
177
|
+
# This gets taken care of semantically by adding an error class to the wrapper tag
|
178
|
+
# containing the input.
|
179
|
+
mattr_accessor :field_error_proc
|
180
|
+
@@field_error_proc = proc do |html_tag, instance_tag|
|
181
|
+
html_tag
|
182
|
+
end
|
183
|
+
|
184
|
+
# Adds a class to each generated inputs
|
185
|
+
mattr_accessor :input_class
|
186
|
+
@@input_class = nil
|
187
|
+
|
188
|
+
# Defines if an input wrapper class should be included or not
|
189
|
+
mattr_accessor :include_default_input_wrapper_class
|
190
|
+
@@include_default_input_wrapper_class = true
|
191
|
+
|
192
|
+
# Define the default class of the input wrapper of the boolean input.
|
193
|
+
mattr_accessor :boolean_label_class
|
194
|
+
@@boolean_label_class = 'checkbox'
|
195
|
+
|
136
196
|
## WRAPPER CONFIGURATION
|
137
197
|
# The default wrapper to be used by the FormBuilder.
|
138
198
|
mattr_accessor :default_wrapper
|
139
199
|
@@default_wrapper = :default
|
140
|
-
@@wrappers = {}
|
200
|
+
@@wrappers = {} #:nodoc:
|
201
|
+
|
202
|
+
mattr_accessor :i18n_scope
|
203
|
+
@@i18n_scope = 'simple_form'
|
141
204
|
|
142
205
|
# Retrieves a given wrapper
|
143
206
|
def self.wrapper(name)
|
144
|
-
@@wrappers[name.
|
207
|
+
@@wrappers[name.to_s] or raise WrapperNotFound, "Couldn't find wrapper with name #{name}"
|
145
208
|
end
|
146
209
|
|
147
210
|
# Raised when fails to find a given wrapper name
|
@@ -154,21 +217,21 @@ module SimpleForm
|
|
154
217
|
if block_given?
|
155
218
|
options = args.extract_options!
|
156
219
|
name = args.first || :default
|
157
|
-
@@wrappers[name.
|
220
|
+
@@wrappers[name.to_s] = build(options, &block)
|
158
221
|
else
|
159
222
|
@@wrappers
|
160
223
|
end
|
161
224
|
end
|
162
225
|
|
163
226
|
# Builds a new wrapper using SimpleForm::Wrappers::Builder.
|
164
|
-
def self.build(options={})
|
227
|
+
def self.build(options = {})
|
165
228
|
options[:tag] = :div if options[:tag].nil?
|
166
229
|
builder = SimpleForm::Wrappers::Builder.new(options)
|
167
230
|
yield builder
|
168
231
|
SimpleForm::Wrappers::Root.new(builder.to_a, options)
|
169
232
|
end
|
170
233
|
|
171
|
-
wrappers :
|
234
|
+
wrappers class: :input, hint_class: :field_with_hint, error_class: :field_with_errors do |b|
|
172
235
|
b.use :html5
|
173
236
|
|
174
237
|
b.use :min_max
|
@@ -178,47 +241,31 @@ module SimpleForm
|
|
178
241
|
b.optional :readonly
|
179
242
|
|
180
243
|
b.use :label_input
|
181
|
-
b.use :hint, :
|
182
|
-
b.use :error, :
|
183
|
-
end
|
184
|
-
|
185
|
-
## SETUP
|
186
|
-
|
187
|
-
DEPRECATED = %w(hint_tag hint_class error_tag error_class error_notification_id wrapper_tag wrapper_class wrapper_error_class components html5)
|
188
|
-
@@deprecated = []
|
189
|
-
|
190
|
-
DEPRECATED.each do |method|
|
191
|
-
class_eval "def self.#{method}=(*); @@deprecated << :#{method}=; end"
|
192
|
-
class_eval "def self.#{method}; deprecation_warn 'SimpleForm.#{method} is deprecated and has no effect'; end"
|
244
|
+
b.use :hint, wrap_with: { tag: :span, class: :hint }
|
245
|
+
b.use :error, wrap_with: { tag: :span, class: :error }
|
193
246
|
end
|
194
247
|
|
195
|
-
def self.
|
196
|
-
|
197
|
-
self.translate_labels = value
|
248
|
+
def self.additional_classes_for(component)
|
249
|
+
generate_additional_classes_for.include?(component) ? yield : []
|
198
250
|
end
|
199
251
|
|
200
|
-
|
201
|
-
deprecation_warn "SimpleForm.translate is disabled in favor of translate_labels"
|
202
|
-
self.translate_labels
|
203
|
-
end
|
252
|
+
## SETUP
|
204
253
|
|
205
|
-
def self.
|
206
|
-
ActiveSupport::Deprecation.warn "[SIMPLE_FORM]
|
254
|
+
def self.default_input_size=(*)
|
255
|
+
ActiveSupport::Deprecation.warn "[SIMPLE_FORM] SimpleForm.default_input_size= is deprecated and has no effect", caller
|
207
256
|
end
|
208
257
|
|
209
|
-
def self.
|
210
|
-
|
258
|
+
def self.form_class=(value)
|
259
|
+
ActiveSupport::Deprecation.warn "[SIMPLE_FORM] SimpleForm.form_class= is deprecated and will be removed in 4.x. Use SimpleForm.default_form_class= instead", caller
|
260
|
+
@@form_class = value
|
211
261
|
end
|
212
262
|
|
213
|
-
# Default way to setup
|
263
|
+
# Default way to setup Simple Form. Run rails generate simple_form:install
|
214
264
|
# to create a fresh initializer with all configuration values.
|
215
265
|
def self.setup
|
266
|
+
@@configured = true
|
216
267
|
yield self
|
217
|
-
|
218
|
-
unless @@deprecated.empty?
|
219
|
-
raise "[SIMPLE FORM] Your SimpleForm initializer file is using the following methods: #{@@deprecated.to_sentence}. " <<
|
220
|
-
"Those methods are part of the outdated configuration API. Updating to the new API is easy and fast. " <<
|
221
|
-
"Check for more info here: https://github.com/plataformatec/simple_form/wiki/Upgrading-to-Simple-Form-2.0"
|
222
|
-
end
|
223
268
|
end
|
224
269
|
end
|
270
|
+
|
271
|
+
require 'simple_form/railtie' if defined?(Rails)
|