simple_form 2.0.0 → 2.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 (60) hide show
  1. data/CHANGELOG.md +34 -231
  2. data/MIT-LICENSE +1 -1
  3. data/README.md +221 -159
  4. data/lib/generators/simple_form/install_generator.rb +14 -5
  5. data/lib/generators/simple_form/templates/config/initializers/{simple_form.rb.tt → simple_form.rb} +8 -42
  6. data/lib/generators/simple_form/templates/config/initializers/simple_form_bootstrap.rb +45 -0
  7. data/lib/generators/simple_form/templates/config/initializers/simple_form_foundation.rb +26 -0
  8. data/lib/generators/simple_form/templates/config/locales/simple_form.en.yml +7 -5
  9. data/lib/simple_form/action_view_extensions/builder.rb +46 -30
  10. data/lib/simple_form/action_view_extensions/builder.rb.orig +247 -0
  11. data/lib/simple_form/action_view_extensions/form_helper.rb +7 -9
  12. data/lib/simple_form/components/hints.rb +3 -2
  13. data/lib/simple_form/components/label_input.rb +1 -1
  14. data/lib/simple_form/components/labels.rb +1 -1
  15. data/lib/simple_form/components/maxlength.rb +1 -1
  16. data/lib/simple_form/components/min_max.rb +2 -1
  17. data/lib/simple_form/components/pattern.rb +1 -1
  18. data/lib/simple_form/components/readonly.rb +1 -1
  19. data/lib/simple_form/components.rb +12 -10
  20. data/lib/simple_form/error_notification.rb +1 -1
  21. data/lib/simple_form/form_builder.rb +18 -8
  22. data/lib/simple_form/form_builder.rb.orig +486 -0
  23. data/lib/simple_form/helpers/validators.rb +2 -2
  24. data/lib/simple_form/inputs/base.rb +33 -8
  25. data/lib/simple_form/inputs/boolean_input.rb +19 -5
  26. data/lib/simple_form/inputs/collection_radio_buttons_input.rb +2 -6
  27. data/lib/simple_form/inputs/date_time_input.rb +0 -4
  28. data/lib/simple_form/inputs.rb +19 -17
  29. data/lib/simple_form/version.rb +1 -1
  30. data/lib/simple_form/version.rb.orig +7 -0
  31. data/lib/simple_form/wrappers/many.rb +5 -1
  32. data/lib/simple_form/wrappers/root.rb +4 -2
  33. data/lib/simple_form/wrappers/single.rb +6 -0
  34. data/lib/simple_form.rb +17 -8
  35. data/test/action_view_extensions/builder_test.rb +145 -66
  36. data/test/action_view_extensions/form_helper_test.rb +59 -20
  37. data/test/components/label_test.rb +34 -17
  38. data/test/form_builder/association_test.rb +19 -10
  39. data/test/form_builder/error_notification_test.rb +1 -1
  40. data/test/form_builder/general_test.rb +74 -12
  41. data/test/form_builder/hint_test.rb +15 -0
  42. data/test/form_builder/input_field_test.rb +45 -0
  43. data/test/form_builder/label_test.rb +6 -0
  44. data/test/form_builder/wrapper_test.rb +58 -4
  45. data/test/generators/simple_form_generator_test.rb +11 -1
  46. data/test/inputs/boolean_input_test.rb +39 -0
  47. data/test/inputs/datetime_input_test.rb +2 -2
  48. data/test/inputs/disabled_test.rb +51 -11
  49. data/test/inputs/discovery_test.rb +9 -1
  50. data/test/inputs/general_test.rb +58 -11
  51. data/test/inputs/grouped_collection_select_input_test.rb +15 -0
  52. data/test/inputs/numeric_input_test.rb +6 -0
  53. data/test/inputs/readonly_test.rb +51 -11
  54. data/test/inputs/string_input_test.rb +6 -0
  55. data/test/support/discovery_inputs.rb +6 -0
  56. data/test/support/misc_helpers.rb +41 -1
  57. data/test/support/models.rb +8 -4
  58. data/test/test_helper.rb +8 -6
  59. metadata +26 -13
  60. data/test/support/mock_response.rb +0 -14
@@ -5,7 +5,7 @@ module SimpleForm
5
5
  if nested_boolean_style?
6
6
  build_hidden_field_for_checkbox +
7
7
  template.label_tag(nil, :class => "checkbox") {
8
- build_check_box_without_hidden_field
8
+ build_check_box_without_hidden_field + inline_label
9
9
  }
10
10
  else
11
11
  build_check_box
@@ -34,8 +34,8 @@ module SimpleForm
34
34
  # reuse the method for nested boolean style, but with no unchecked value,
35
35
  # which won't generate the hidden checkbox. This is the default functionality
36
36
  # in Rails > 3.2.1, and is backported in SimpleForm AV helpers.
37
- def build_check_box(unchecked_value='0')
38
- @builder.check_box(attribute_name, input_html_options, '1', unchecked_value)
37
+ def build_check_box(unchecked_value = unchecked_value)
38
+ @builder.check_box(attribute_name, input_html_options, checked_value, unchecked_value)
39
39
  end
40
40
 
41
41
  # Build a checkbox without generating the hidden field. See
@@ -49,8 +49,14 @@ module SimpleForm
49
49
  # we need the hidden field to be *outside* the label (otherwise it
50
50
  # generates invalid html - html5 only).
51
51
  def build_hidden_field_for_checkbox
52
- @builder.hidden_field(attribute_name, :value => '0', :id => nil,
53
- :disabled => input_html_options[:disabled])
52
+ @builder.hidden_field(attribute_name, :value => unchecked_value, :id => nil,
53
+ :disabled => input_html_options[:disabled],
54
+ :name => input_html_options[:name])
55
+ end
56
+
57
+ def inline_label
58
+ inline_option = options[:inline_label]
59
+ inline_option == true ? label_text : inline_option
54
60
  end
55
61
 
56
62
  # Booleans are not required by default because in most of the cases
@@ -59,6 +65,14 @@ module SimpleForm
59
65
  def required_by_default?
60
66
  false
61
67
  end
68
+
69
+ def checked_value
70
+ options.fetch(:checked_value, '1')
71
+ end
72
+
73
+ def unchecked_value
74
+ options.fetch(:unchecked_value, '0')
75
+ end
62
76
  end
63
77
  end
64
78
  end
@@ -20,16 +20,12 @@ module SimpleForm
20
20
  protected
21
21
 
22
22
  def apply_default_collection_options!(options)
23
- unless options.key?(:item_wrapper_tag)
24
- options[:item_wrapper_tag] = SimpleForm.item_wrapper_tag
25
- end
23
+ options[:item_wrapper_tag] ||= options.fetch(:item_wrapper_tag, SimpleForm.item_wrapper_tag)
26
24
  options[:item_wrapper_class] = [
27
25
  item_wrapper_class, options[:item_wrapper_class], SimpleForm.item_wrapper_class
28
26
  ].compact.presence
29
27
 
30
- unless options.key?(:collection_wrapper_tag)
31
- options[:collection_wrapper_tag] = SimpleForm.collection_wrapper_tag
32
- end
28
+ options[:collection_wrapper_tag] ||= options.fetch(:collection_wrapper_tag, SimpleForm.collection_wrapper_tag)
33
29
  options[:collection_wrapper_class] = [
34
30
  options[:collection_wrapper_class], SimpleForm.collection_wrapper_class
35
31
  ].compact.presence
@@ -5,10 +5,6 @@ module SimpleForm
5
5
  @builder.send(:"#{input_type}_select", attribute_name, input_options, input_html_options)
6
6
  end
7
7
 
8
- def has_required?
9
- false
10
- end
11
-
12
8
  private
13
9
 
14
10
  def label_target
@@ -1,21 +1,23 @@
1
1
  module SimpleForm
2
2
  module Inputs
3
- autoload :Base, 'simple_form/inputs/base'
4
- autoload :BlockInput, 'simple_form/inputs/block_input'
5
- autoload :BooleanInput, 'simple_form/inputs/boolean_input'
6
- autoload :CollectionCheckBoxesInput, 'simple_form/inputs/collection_check_boxes_input'
7
- autoload :CollectionInput, 'simple_form/inputs/collection_input'
8
- autoload :CollectionRadioButtonsInput, 'simple_form/inputs/collection_radio_buttons_input'
9
- autoload :CollectionSelectInput, 'simple_form/inputs/collection_select_input'
10
- autoload :DateTimeInput, 'simple_form/inputs/date_time_input'
11
- autoload :FileInput, 'simple_form/inputs/file_input'
12
- autoload :GroupedCollectionSelectInput, 'simple_form/inputs/grouped_collection_select_input'
13
- autoload :HiddenInput, 'simple_form/inputs/hidden_input'
14
- autoload :NumericInput, 'simple_form/inputs/numeric_input'
15
- autoload :PasswordInput, 'simple_form/inputs/password_input'
16
- autoload :PriorityInput, 'simple_form/inputs/priority_input'
17
- autoload :RangeInput, 'simple_form/inputs/range_input'
18
- autoload :StringInput, 'simple_form/inputs/string_input'
19
- autoload :TextInput, 'simple_form/inputs/text_input'
3
+ extend ActiveSupport::Autoload
4
+
5
+ autoload :Base
6
+ autoload :BlockInput
7
+ autoload :BooleanInput
8
+ autoload :CollectionCheckBoxesInput
9
+ autoload :CollectionInput
10
+ autoload :CollectionRadioButtonsInput
11
+ autoload :CollectionSelectInput
12
+ autoload :DateTimeInput
13
+ autoload :FileInput
14
+ autoload :GroupedCollectionSelectInput
15
+ autoload :HiddenInput
16
+ autoload :NumericInput
17
+ autoload :PasswordInput
18
+ autoload :PriorityInput
19
+ autoload :RangeInput
20
+ autoload :StringInput
21
+ autoload :TextInput
20
22
  end
21
23
  end
@@ -1,3 +1,3 @@
1
1
  module SimpleForm
2
- VERSION = "2.0.0".freeze
2
+ VERSION = "2.1.0".freeze
3
3
  end
@@ -0,0 +1,7 @@
1
+ module SimpleForm
2
+ <<<<<<< HEAD
3
+ VERSION = "2.0.4".freeze
4
+ =======
5
+ VERSION = "2.1.0.dev".freeze
6
+ >>>>>>> issue-720
7
+ end
@@ -56,11 +56,15 @@ module SimpleForm
56
56
  return content unless tag
57
57
 
58
58
  klass = html_classes(input, options)
59
- opts = options[:"#{namespace}_html"] || {}
59
+ opts = html_options(options)
60
60
  opts[:class] = (klass << opts[:class]).join(' ').strip unless klass.empty?
61
61
  input.template.content_tag(tag, content, opts)
62
62
  end
63
63
 
64
+ def html_options(options)
65
+ options[:"#{namespace}_html"] || {}
66
+ end
67
+
64
68
  def html_classes(input, options)
65
69
  @defaults[:class].dup
66
70
  end
@@ -24,10 +24,12 @@ module SimpleForm
24
24
 
25
25
  def html_classes(input, options)
26
26
  css = options[:wrapper_class] ? Array.wrap(options[:wrapper_class]) : @defaults[:class]
27
- css += SimpleForm.additional_classes_for(:wrapper) { input.html_classes }
27
+ css += SimpleForm.additional_classes_for(:wrapper) do
28
+ input.additional_classes + [input.input_class]
29
+ end
28
30
  css << (options[:wrapper_error_class] || @defaults[:error_class]) if input.has_errors?
29
31
  css << (options[:wrapper_hint_class] || @defaults[:hint_class]) if input.has_hint?
30
- css
32
+ css.compact
31
33
  end
32
34
  end
33
35
  end
@@ -13,6 +13,12 @@ module SimpleForm
13
13
  wrap(input, options, content) if content
14
14
  end
15
15
  end
16
+
17
+ private
18
+
19
+ def html_options(options)
20
+ [:label, :input].include?(namespace) ? {} : super
21
+ end
16
22
  end
17
23
  end
18
24
  end
data/lib/simple_form.rb CHANGED
@@ -6,14 +6,17 @@ require 'active_support/core_ext/hash/except'
6
6
  require 'active_support/core_ext/hash/reverse_merge'
7
7
 
8
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'
9
+ extend ActiveSupport::Autoload
10
+
11
+ autoload :Helpers
12
+ autoload :Wrappers
13
+
14
+ eager_autoload do
15
+ autoload :Components
16
+ autoload :ErrorNotification
17
+ autoload :FormBuilder
18
+ autoload :Inputs
19
+ end
17
20
 
18
21
  ## CONFIGURATION OPTIONS
19
22
 
@@ -95,6 +98,12 @@ module SimpleForm
95
98
  mattr_accessor :input_mappings
96
99
  @@input_mappings = nil
97
100
 
101
+ # Custom wrappers for input types. This should be a hash containing an input
102
+ # type as key and the wrapper that will be used for all inputs with specified type.
103
+ # e.g { :string => :string_wrapper, :boolean => :boolean_wrapper }
104
+ mattr_accessor :wrapper_mappings
105
+ @@wrapper_mappings = nil
106
+
98
107
  # Default priority for time_zone inputs.
99
108
  mattr_accessor :time_zone_priority
100
109
  @@time_zone_priority = nil