ehoch_simple_form 2.0.2.dev

Sign up to get free protection for your applications and to get access to all the features.
Files changed (97) hide show
  1. data/CHANGELOG.md +257 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.md +797 -0
  4. data/lib/generators/simple_form/USAGE +3 -0
  5. data/lib/generators/simple_form/install_generator.rb +32 -0
  6. data/lib/generators/simple_form/templates/README +12 -0
  7. data/lib/generators/simple_form/templates/_form.html.erb +13 -0
  8. data/lib/generators/simple_form/templates/_form.html.haml +10 -0
  9. data/lib/generators/simple_form/templates/_form.html.slim +10 -0
  10. data/lib/generators/simple_form/templates/config/initializers/simple_form.rb.tt +181 -0
  11. data/lib/generators/simple_form/templates/config/locales/simple_form.en.yml +26 -0
  12. data/lib/simple_form.rb +215 -0
  13. data/lib/simple_form/action_view_extensions/builder.rb +338 -0
  14. data/lib/simple_form/action_view_extensions/form_helper.rb +74 -0
  15. data/lib/simple_form/components.rb +20 -0
  16. data/lib/simple_form/components/errors.rb +35 -0
  17. data/lib/simple_form/components/hints.rb +18 -0
  18. data/lib/simple_form/components/html5.rb +26 -0
  19. data/lib/simple_form/components/label_input.rb +15 -0
  20. data/lib/simple_form/components/labels.rb +79 -0
  21. data/lib/simple_form/components/maxlength.rb +41 -0
  22. data/lib/simple_form/components/min_max.rb +50 -0
  23. data/lib/simple_form/components/pattern.rb +34 -0
  24. data/lib/simple_form/components/placeholders.rb +16 -0
  25. data/lib/simple_form/components/readonly.rb +22 -0
  26. data/lib/simple_form/core_ext/hash.rb +16 -0
  27. data/lib/simple_form/error_notification.rb +48 -0
  28. data/lib/simple_form/form_builder.rb +472 -0
  29. data/lib/simple_form/helpers.rb +12 -0
  30. data/lib/simple_form/helpers/autofocus.rb +11 -0
  31. data/lib/simple_form/helpers/disabled.rb +15 -0
  32. data/lib/simple_form/helpers/readonly.rb +15 -0
  33. data/lib/simple_form/helpers/required.rb +35 -0
  34. data/lib/simple_form/helpers/validators.rb +44 -0
  35. data/lib/simple_form/i18n_cache.rb +22 -0
  36. data/lib/simple_form/inputs.rb +21 -0
  37. data/lib/simple_form/inputs/base.rb +162 -0
  38. data/lib/simple_form/inputs/block_input.rb +14 -0
  39. data/lib/simple_form/inputs/boolean_input.rb +64 -0
  40. data/lib/simple_form/inputs/collection_check_boxes_input.rb +21 -0
  41. data/lib/simple_form/inputs/collection_input.rb +101 -0
  42. data/lib/simple_form/inputs/collection_radio_buttons_input.rb +63 -0
  43. data/lib/simple_form/inputs/collection_select_input.rb +14 -0
  44. data/lib/simple_form/inputs/date_time_input.rb +28 -0
  45. data/lib/simple_form/inputs/file_input.rb +9 -0
  46. data/lib/simple_form/inputs/grouped_collection_select_input.rb +41 -0
  47. data/lib/simple_form/inputs/hidden_input.rb +17 -0
  48. data/lib/simple_form/inputs/numeric_input.rb +24 -0
  49. data/lib/simple_form/inputs/password_input.rb +12 -0
  50. data/lib/simple_form/inputs/priority_input.rb +24 -0
  51. data/lib/simple_form/inputs/range_input.rb +14 -0
  52. data/lib/simple_form/inputs/string_input.rb +23 -0
  53. data/lib/simple_form/inputs/text_input.rb +11 -0
  54. data/lib/simple_form/map_type.rb +16 -0
  55. data/lib/simple_form/version.rb +3 -0
  56. data/lib/simple_form/wrappers.rb +8 -0
  57. data/lib/simple_form/wrappers/builder.rb +103 -0
  58. data/lib/simple_form/wrappers/many.rb +69 -0
  59. data/lib/simple_form/wrappers/root.rb +34 -0
  60. data/lib/simple_form/wrappers/single.rb +18 -0
  61. data/test/action_view_extensions/builder_test.rb +577 -0
  62. data/test/action_view_extensions/form_helper_test.rb +104 -0
  63. data/test/components/label_test.rb +310 -0
  64. data/test/form_builder/association_test.rb +177 -0
  65. data/test/form_builder/button_test.rb +47 -0
  66. data/test/form_builder/error_notification_test.rb +79 -0
  67. data/test/form_builder/error_test.rb +121 -0
  68. data/test/form_builder/general_test.rb +356 -0
  69. data/test/form_builder/hint_test.rb +139 -0
  70. data/test/form_builder/input_field_test.rb +63 -0
  71. data/test/form_builder/label_test.rb +71 -0
  72. data/test/form_builder/wrapper_test.rb +149 -0
  73. data/test/generators/simple_form_generator_test.rb +32 -0
  74. data/test/inputs/boolean_input_test.rb +108 -0
  75. data/test/inputs/collection_check_boxes_input_test.rb +224 -0
  76. data/test/inputs/collection_radio_buttons_input_test.rb +326 -0
  77. data/test/inputs/collection_select_input_test.rb +241 -0
  78. data/test/inputs/datetime_input_test.rb +99 -0
  79. data/test/inputs/disabled_test.rb +38 -0
  80. data/test/inputs/discovery_test.rb +61 -0
  81. data/test/inputs/file_input_test.rb +16 -0
  82. data/test/inputs/general_test.rb +69 -0
  83. data/test/inputs/grouped_collection_select_input_test.rb +118 -0
  84. data/test/inputs/hidden_input_test.rb +30 -0
  85. data/test/inputs/numeric_input_test.rb +173 -0
  86. data/test/inputs/priority_input_test.rb +43 -0
  87. data/test/inputs/readonly_test.rb +61 -0
  88. data/test/inputs/required_test.rb +113 -0
  89. data/test/inputs/string_input_test.rb +140 -0
  90. data/test/inputs/text_input_test.rb +24 -0
  91. data/test/simple_form_test.rb +9 -0
  92. data/test/support/discovery_inputs.rb +21 -0
  93. data/test/support/misc_helpers.rb +102 -0
  94. data/test/support/mock_controller.rb +24 -0
  95. data/test/support/models.rb +210 -0
  96. data/test/test_helper.rb +90 -0
  97. metadata +210 -0
@@ -0,0 +1,3 @@
1
+ To copy a SimpleForm initializer to your Rails App, with some configuration values, just do:
2
+
3
+ rails generate simple_form:install
@@ -0,0 +1,32 @@
1
+ module SimpleForm
2
+ module Generators
3
+ class InstallGenerator < Rails::Generators::Base
4
+ desc "Copy SimpleForm default files"
5
+ source_root File.expand_path('../templates', __FILE__)
6
+ class_option :template_engine, :desc => 'Template engine to be invoked (erb, haml or slim).'
7
+ class_option :bootstrap, :type => :boolean, :desc => 'Add the Twitter Bootstrap wrappers to the SimpleForm initializer.'
8
+
9
+ def info_bootstrap
10
+ return if options.bootstrap?
11
+ puts "SimpleForm 2 supports Twitter bootstrap. In case you want to " \
12
+ "generate bootstrap configuration, please re-run this " \
13
+ "generator passing --bootstrap as option."
14
+ end
15
+
16
+ def copy_config
17
+ directory 'config'
18
+ end
19
+
20
+ def copy_scaffold_template
21
+ engine = options[:template_engine]
22
+ copy_file "_form.html.#{engine}", "lib/templates/#{engine}/scaffold/_form.html.#{engine}"
23
+ end
24
+
25
+ def show_readme
26
+ if behavior == :invoke && options.bootstrap?
27
+ readme "README"
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,12 @@
1
+ ===============================================================================
2
+
3
+ Be sure to have a copy of the Bootstrap stylesheet available on your
4
+ application, you can get it on http://twitter.github.com/bootstrap.
5
+
6
+ Inside your views, use the 'simple_form_for' with one of the Bootstrap form
7
+ classes, '.form-horizontal', '.form-inline', '.form-search' or
8
+ '.form-vertical', as the following:
9
+
10
+ = simple_form_for(@user, :html => {:class => 'form-horizontal' }) do |form|
11
+
12
+ ===============================================================================
@@ -0,0 +1,13 @@
1
+ <%%= simple_form_for(@<%= singular_table_name %>) do |f| %>
2
+ <%%= f.error_notification %>
3
+
4
+ <div class="form-inputs">
5
+ <%- attributes.each do |attribute| -%>
6
+ <%%= f.<%= attribute.reference? ? :association : :input %> :<%= attribute.name %> %>
7
+ <%- end -%>
8
+ </div>
9
+
10
+ <div class="form-actions">
11
+ <%%= f.button :submit %>
12
+ </div>
13
+ <%% end %>
@@ -0,0 +1,10 @@
1
+ = simple_form_for(@<%= singular_table_name %>) do |f|
2
+ = f.error_notification
3
+
4
+ .form-inputs
5
+ <%- attributes.each do |attribute| -%>
6
+ = f.<%= attribute.reference? ? :association : :input %> :<%= attribute.name %>
7
+ <%- end -%>
8
+
9
+ .form-actions
10
+ = f.button :submit
@@ -0,0 +1,10 @@
1
+ = simple_form_for(@<%= singular_table_name %>) do |f|
2
+ = f.error_notification
3
+
4
+ .form-inputs
5
+ <%- attributes.each do |attribute| -%>
6
+ = f.<%= attribute.reference? ? :association : :input %> :<%= attribute.name %>
7
+ <%- end -%>
8
+
9
+ .form-actions
10
+ = f.button :submit
@@ -0,0 +1,181 @@
1
+ # Use this setup block to configure all options available in SimpleForm.
2
+ SimpleForm.setup do |config|
3
+ # Wrappers are used by the form builder to generate a
4
+ # complete input. You can remove any component from the
5
+ # wrapper, change the order or even add your own to the
6
+ # stack. The options given below are used to wrap the
7
+ # whole input.
8
+ config.wrappers :default, :class => :input,
9
+ :hint_class => :field_with_hint, :error_class => :field_with_errors do |b|
10
+ ## Extensions enabled by default
11
+ # Any of these extensions can be disabled for a
12
+ # given input by passing: `f.input EXTENSION_NAME => false`.
13
+ # You can make any of these extensions optional by
14
+ # renaming `b.use` to `b.optional`.
15
+
16
+ # Determines whether to use HTML5 (:email, :url, ...)
17
+ # and required attributes
18
+ b.use :html5
19
+
20
+ # Calculates placeholders automatically from I18n
21
+ # You can also pass a string as f.input :placeholder => "Placeholder"
22
+ b.use :placeholder
23
+
24
+ ## Optional extensions
25
+ # They are disabled unless you pass `f.input EXTENSION_NAME => :lookup`
26
+ # to the input. If so, they will retrieve the values from the model
27
+ # if any exists. If you want to enable the lookup for any of those
28
+ # extensions by default, you can change `b.optional` to `b.use`.
29
+
30
+ # Calculates maxlength from length validations for string inputs
31
+ b.optional :maxlength
32
+
33
+ # Calculates pattern from format validations for string inputs
34
+ b.optional :pattern
35
+
36
+ # Calculates min and max from length validations for numeric inputs
37
+ b.optional :min_max
38
+
39
+ # Calculates readonly automatically from readonly attributes
40
+ b.optional :readonly
41
+
42
+ ## Inputs
43
+ b.use :label_input
44
+ b.use :hint, :wrap_with => { :tag => :span, :class => :hint }
45
+ b.use :error, :wrap_with => { :tag => :span, :class => :error }
46
+ end
47
+ <% if options.bootstrap? %>
48
+ config.wrappers :bootstrap, :tag => 'div', :class => 'control-group', :error_class => 'error' do |b|
49
+ b.use :html5
50
+ b.use :placeholder
51
+ b.use :label
52
+ b.wrapper :tag => 'div', :class => 'controls' do |ba|
53
+ ba.use :input
54
+ ba.use :error, :wrap_with => { :tag => 'span', :class => 'help-inline' }
55
+ ba.use :hint, :wrap_with => { :tag => 'p', :class => 'help-block' }
56
+ end
57
+ end
58
+
59
+ config.wrappers :prepend, :tag => 'div', :class => "control-group", :error_class => 'error' do |b|
60
+ b.use :html5
61
+ b.use :placeholder
62
+ b.use :label
63
+ b.wrapper :tag => 'div', :class => 'controls' do |input|
64
+ input.wrapper :tag => 'div', :class => 'input-prepend' do |prepend|
65
+ prepend.use :input
66
+ end
67
+ input.use :hint, :wrap_with => { :tag => 'span', :class => 'help-block' }
68
+ input.use :error, :wrap_with => { :tag => 'span', :class => 'help-inline' }
69
+ end
70
+ end
71
+
72
+ config.wrappers :append, :tag => 'div', :class => "control-group", :error_class => 'error' do |b|
73
+ b.use :html5
74
+ b.use :placeholder
75
+ b.use :label
76
+ b.wrapper :tag => 'div', :class => 'controls' do |input|
77
+ input.wrapper :tag => 'div', :class => 'input-append' do |append|
78
+ append.use :input
79
+ end
80
+ input.use :hint, :wrap_with => { :tag => 'span', :class => 'help-block' }
81
+ input.use :error, :wrap_with => { :tag => 'span', :class => 'help-inline' }
82
+ end
83
+ end
84
+
85
+ # Wrappers for forms and inputs using the Twitter Bootstrap toolkit.
86
+ # Check the Bootstrap docs (http://twitter.github.com/bootstrap)
87
+ # to learn about the different styles for forms and inputs,
88
+ # buttons and other elements.
89
+ config.default_wrapper = :bootstrap
90
+ <% else %>
91
+ # The default wrapper to be used by the FormBuilder.
92
+ config.default_wrapper = :default
93
+ <% end %>
94
+ # Define the way to render check boxes / radio buttons with labels.
95
+ # Defaults to :nested for bootstrap config.
96
+ # :inline => input + label
97
+ # :nested => label > input
98
+ config.boolean_style = :nested
99
+
100
+ # Default class for buttons
101
+ config.button_class = 'btn'
102
+
103
+ # Method used to tidy up errors. Specify any Rails Array method.
104
+ # :first lists the first message for each field.
105
+ # Use :to_sentence to list all errors for each field.
106
+ # config.error_method = :first
107
+
108
+ # Default tag used for error notification helper.
109
+ config.error_notification_tag = :div
110
+
111
+ # CSS class to add for error notification helper.
112
+ config.error_notification_class = 'alert alert-error'
113
+
114
+ # ID to add for error notification helper.
115
+ # config.error_notification_id = nil
116
+
117
+ # Series of attempts to detect a default label method for collection.
118
+ # config.collection_label_methods = [ :to_label, :name, :title, :to_s ]
119
+
120
+ # Series of attempts to detect a default value method for collection.
121
+ # config.collection_value_methods = [ :id, :to_s ]
122
+
123
+ # You can wrap a collection of radio/check boxes in a pre-defined tag, defaulting to none.
124
+ # config.collection_wrapper_tag = nil
125
+
126
+ # You can define the class to use on all collection wrappers. Defaulting to none.
127
+ # config.collection_wrapper_class = nil
128
+
129
+ # You can wrap each item in a collection of radio/check boxes with a tag,
130
+ # defaulting to :span. Please note that when using :boolean_style = :nested,
131
+ # SimpleForm will force this option to be a label.
132
+ # config.item_wrapper_tag = :span
133
+
134
+ # You can define a class to use in all item wrappers. Defaulting to none.
135
+ # config.item_wrapper_class = nil
136
+
137
+ # How the label text should be generated altogether with the required text.
138
+ # config.label_text = lambda { |label, required| "#{required} #{label}" }
139
+
140
+ # You can define the class to use on all labels. Default is nil.
141
+ config.label_class = 'control-label'
142
+
143
+ # You can define the class to use on all forms. Default is simple_form.
144
+ # config.form_class = :simple_form
145
+
146
+ # You can define which elements should obtain additional classes
147
+ # config.generate_additional_classes_for = [:wrapper, :label, :input]
148
+
149
+ # Whether attributes are required by default (or not). Default is true.
150
+ # config.required_by_default = true
151
+
152
+ # Tell browsers whether to use default HTML5 validations (novalidate option).
153
+ # Default is enabled.
154
+ config.browser_validations = false
155
+
156
+ # Collection of methods to detect if a file type was given.
157
+ # config.file_methods = [ :mounted_as, :file?, :public_filename ]
158
+
159
+ # Custom mappings for input types. This should be a hash containing a regexp
160
+ # to match as key, and the input type that will be used when the field name
161
+ # matches the regexp as value.
162
+ # config.input_mappings = { /count/ => :integer }
163
+
164
+ # Default priority for time_zone inputs.
165
+ # config.time_zone_priority = nil
166
+
167
+ # Default priority for country inputs.
168
+ # config.country_priority = nil
169
+
170
+ # Default size for text inputs.
171
+ # config.default_input_size = 50
172
+
173
+ # When false, do not use translations for labels.
174
+ # config.translate_labels = true
175
+
176
+ # Automatically discover new inputs in Rails' autoload path.
177
+ # config.inputs_discovery = true
178
+
179
+ # Cache SimpleForm inputs discovery
180
+ # config.cache_discovery = !Rails.env.development?
181
+ end
@@ -0,0 +1,26 @@
1
+ en:
2
+ simple_form:
3
+ "yes": 'Yes'
4
+ "no": 'No'
5
+ required:
6
+ text: 'required'
7
+ mark: '*'
8
+ # You can uncomment the line below if you need to overwrite the whole required html.
9
+ # When using html, text and mark won't be used.
10
+ # html: '<abbr title="required">*</abbr>'
11
+ error_notification:
12
+ default_message: "Some errors were found, please take a look:"
13
+ # Labels and hints examples
14
+ # labels:
15
+ # defaults:
16
+ # password: 'Password'
17
+ # user:
18
+ # new:
19
+ # email: 'E-mail to sign in.'
20
+ # edit:
21
+ # email: 'E-mail.'
22
+ # hints:
23
+ # defaults:
24
+ # username: 'User name to sign in.'
25
+ # password: 'No special characters, please.'
26
+
@@ -0,0 +1,215 @@
1
+ require 'action_view'
2
+ require 'simple_form/action_view_extensions/form_helper'
3
+ require 'simple_form/action_view_extensions/builder'
4
+ require 'active_support/core_ext/hash/slice'
5
+ require 'active_support/core_ext/hash/except'
6
+ require 'active_support/core_ext/hash/reverse_merge'
7
+
8
+ module SimpleForm
9
+ autoload :Components, 'simple_form/components'
10
+ autoload :ErrorNotification, 'simple_form/error_notification'
11
+ autoload :FormBuilder, 'simple_form/form_builder'
12
+ autoload :Helpers, 'simple_form/helpers'
13
+ autoload :I18nCache, 'simple_form/i18n_cache'
14
+ autoload :Inputs, 'simple_form/inputs'
15
+ autoload :MapType, 'simple_form/map_type'
16
+ autoload :Wrappers, 'simple_form/wrappers'
17
+
18
+ ## CONFIGURATION OPTIONS
19
+
20
+ # Method used to tidy up errors.
21
+ mattr_accessor :error_method
22
+ @@error_method = :first
23
+
24
+ # Default tag used for error notification helper.
25
+ mattr_accessor :error_notification_tag
26
+ @@error_notification_tag = :p
27
+
28
+ # CSS class to add for error notification helper.
29
+ mattr_accessor :error_notification_class
30
+ @@error_notification_class = :error_notification
31
+
32
+ # Series of attemps to detect a default label method for collection.
33
+ mattr_accessor :collection_label_methods
34
+ @@collection_label_methods = [ :to_label, :name, :title, :to_s ]
35
+
36
+ # Series of attemps to detect a default value method for collection.
37
+ mattr_accessor :collection_value_methods
38
+ @@collection_value_methods = [ :id, :to_s ]
39
+
40
+ # You can wrap a collection of radio/check boxes in a pre-defined tag, defaulting to none.
41
+ mattr_accessor :collection_wrapper_tag
42
+ @@collection_wrapper_tag = nil
43
+
44
+ # You can define the class to use on all collection wrappers, defaulting to none.
45
+ mattr_accessor :collection_wrapper_class
46
+ @@collection_wrapper_class = nil
47
+
48
+ # You can wrap each item in a collection of radio/check boxes with a tag,
49
+ # defaulting to none. Please note that when using :boolean_style = :nested,
50
+ # SimpleForm will force this option to be a :label.
51
+ mattr_accessor :item_wrapper_tag
52
+ @@item_wrapper_tag = :span
53
+
54
+ # You can define the class to use on all item wrappers, defaulting to none.
55
+ mattr_accessor :item_wrapper_class
56
+ @@item_wrapper_class = nil
57
+
58
+ # How the label text should be generated altogether with the required text.
59
+ mattr_accessor :label_text
60
+ @@label_text = lambda { |label, required| "#{required} #{label}" }
61
+
62
+ # You can define the class to use on all labels. Default is nil.
63
+ mattr_accessor :label_class
64
+ @@label_class = nil
65
+
66
+ # Define the way to render check boxes / radio buttons with labels.
67
+ # :inline => input + label (default)
68
+ # :nested => label > input
69
+ mattr_accessor :boolean_style
70
+ @@boolean_style = :inline
71
+
72
+ # You can define the class to use on all forms. Default is simple_form.
73
+ mattr_accessor :form_class
74
+ @@form_class = :simple_form
75
+
76
+ # You can define which elements should obtain additional classes
77
+ mattr_accessor :generate_additional_classes_for
78
+ @@generate_additional_classes_for = [:wrapper, :label, :input]
79
+
80
+ # Whether attributes are required by default (or not).
81
+ mattr_accessor :required_by_default
82
+ @@required_by_default = true
83
+
84
+ # Tell browsers whether to use default HTML5 validations (novalidate option).
85
+ mattr_accessor :browser_validations
86
+ @@browser_validations = true
87
+
88
+ # Collection of methods to detect if a file type was given.
89
+ mattr_accessor :file_methods
90
+ @@file_methods = [ :mounted_as, :file?, :public_filename ]
91
+
92
+ # Custom mappings for input types. This should be a hash containing a regexp
93
+ # to match as key, and the input type that will be used when the field name
94
+ # matches the regexp as value, such as { /count/ => :integer }.
95
+ mattr_accessor :input_mappings
96
+ @@input_mappings = nil
97
+
98
+ # Default priority for time_zone inputs.
99
+ mattr_accessor :time_zone_priority
100
+ @@time_zone_priority = nil
101
+
102
+ # Default priority for country inputs.
103
+ mattr_accessor :country_priority
104
+ @@country_priority = nil
105
+
106
+ # Maximum size allowed for inputs.
107
+ mattr_accessor :default_input_size
108
+ @@default_input_size = 50
109
+
110
+ # When off, do not use translations in labels. Disabling translation in
111
+ # hints and placeholders can be done manually in the wrapper API.
112
+ mattr_accessor :translate_labels
113
+ @@translate_labels = true
114
+
115
+ # Automatically discover new inputs in Rails' autoload path.
116
+ mattr_accessor :inputs_discovery
117
+ @@inputs_discovery = true
118
+
119
+ # Cache SimpleForm inputs discovery
120
+ mattr_accessor :cache_discovery
121
+ @@cache_discovery = defined?(Rails) && !Rails.env.development?
122
+
123
+ # Adds a class to each generated button, mostly for compatiblity
124
+ mattr_accessor :button_class
125
+ @@button_class = 'button'
126
+
127
+ ## WRAPPER CONFIGURATION
128
+ # The default wrapper to be used by the FormBuilder.
129
+ mattr_accessor :default_wrapper
130
+ @@default_wrapper = :default
131
+ @@wrappers = {}
132
+
133
+ # Retrieves a given wrapper
134
+ def self.wrapper(name)
135
+ @@wrappers[name.to_sym] or raise WrapperNotFound, "Couldn't find wrapper with name #{name}"
136
+ end
137
+
138
+ # Raised when fails to find a given wrapper name
139
+ class WrapperNotFound < StandardError
140
+ end
141
+
142
+ # Define a new wrapper using SimpleForm::Wrappers::Builder
143
+ # and store it in the given name.
144
+ def self.wrappers(*args, &block)
145
+ if block_given?
146
+ options = args.extract_options!
147
+ name = args.first || :default
148
+ @@wrappers[name.to_sym] = build(options, &block)
149
+ else
150
+ @@wrappers
151
+ end
152
+ end
153
+
154
+ # Builds a new wrapper using SimpleForm::Wrappers::Builder.
155
+ def self.build(options={})
156
+ options[:tag] = :div if options[:tag].nil?
157
+ builder = SimpleForm::Wrappers::Builder.new(options)
158
+ yield builder
159
+ SimpleForm::Wrappers::Root.new(builder.to_a, options)
160
+ end
161
+
162
+ wrappers :class => :input, :hint_class => :field_with_hint, :error_class => :field_with_errors do |b|
163
+ b.use :html5
164
+
165
+ b.use :min_max
166
+ b.use :maxlength
167
+ b.use :placeholder
168
+ b.optional :pattern
169
+ b.optional :readonly
170
+
171
+ b.use :label_input
172
+ b.use :hint, :wrap_with => { :tag => :span, :class => :hint }
173
+ b.use :error, :wrap_with => { :tag => :span, :class => :error }
174
+ end
175
+
176
+ ## SETUP
177
+
178
+ DEPRECATED = %w(hint_tag hint_class error_tag error_class error_notification_id wrapper_tag wrapper_class wrapper_error_class components html5)
179
+ @@deprecated = []
180
+
181
+ DEPRECATED.each do |method|
182
+ class_eval "def self.#{method}=(*); @@deprecated << :#{method}=; end"
183
+ class_eval "def self.#{method}; deprecation_warn 'SimpleForm.#{method} is deprecated and has no effect'; end"
184
+ end
185
+
186
+ def self.translate=(value)
187
+ deprecation_warn "SimpleForm.translate= is disabled in favor of translate_labels="
188
+ self.translate_labels = value
189
+ end
190
+
191
+ def self.translate
192
+ deprecation_warn "SimpleForm.translate is disabled in favor of translate_labels"
193
+ self.translate_labels
194
+ end
195
+
196
+ def self.deprecation_warn(message)
197
+ ActiveSupport::Deprecation.warn "[SIMPLE_FORM] #{message}", caller
198
+ end
199
+
200
+ def self.additional_classes_for(component)
201
+ generate_additional_classes_for.include?(component) ? yield : []
202
+ end
203
+
204
+ # Default way to setup SimpleForm. Run rails generate simple_form:install
205
+ # to create a fresh initializer with all configuration values.
206
+ def self.setup
207
+ yield self
208
+
209
+ unless @@deprecated.empty?
210
+ raise "[SIMPLE FORM] Your SimpleForm initializer file is using the following methods: #{@@deprecated.to_sentence}. " <<
211
+ "Those methods are part of the outdated configuration API. Updating to the new API is easy and fast. " <<
212
+ "Check for more info here: https://github.com/plataformatec/simple_form/wiki/Upgrading-to-Simple-Form-2.0"
213
+ end
214
+ end
215
+ end