formtastic 2.3.1 → 3.0.0.rc

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 (39) hide show
  1. checksums.yaml +8 -8
  2. data/.travis.yml +0 -24
  3. data/Appraisals +0 -8
  4. data/CHANGELOG +0 -16
  5. data/README.textile +2 -2
  6. data/formtastic.gemspec +9 -8
  7. data/lib/formtastic.rb +1 -2
  8. data/lib/formtastic/actions/button_action.rb +1 -8
  9. data/lib/formtastic/helpers/input_helper.rb +2 -0
  10. data/lib/formtastic/inputs.rb +1 -0
  11. data/lib/formtastic/inputs/base.rb +1 -9
  12. data/lib/formtastic/inputs/base/collections.rb +5 -17
  13. data/lib/formtastic/inputs/base/errors.rb +3 -3
  14. data/lib/formtastic/inputs/base/hints.rb +1 -1
  15. data/lib/formtastic/inputs/base/options.rb +1 -1
  16. data/lib/formtastic/inputs/boolean_input.rb +1 -3
  17. data/lib/formtastic/inputs/color_input.rb +42 -0
  18. data/lib/formtastic/inputs/datetime_picker_input.rb +4 -1
  19. data/lib/formtastic/inputs/hidden_input.rb +2 -6
  20. data/lib/formtastic/inputs/select_input.rb +1 -25
  21. data/lib/formtastic/localizer.rb +2 -0
  22. data/lib/formtastic/util.rb +1 -1
  23. data/lib/formtastic/version.rb +1 -1
  24. data/lib/generators/formtastic/install/install_generator.rb +4 -19
  25. data/spec/actions/generic_action_spec.rb +38 -2
  26. data/spec/helpers/input_helper_spec.rb +6 -29
  27. data/spec/inputs/boolean_input_spec.rb +28 -42
  28. data/spec/inputs/color_input_spec.rb +97 -0
  29. data/spec/inputs/hidden_input_spec.rb +11 -28
  30. data/spec/inputs/select_input_spec.rb +6 -107
  31. data/spec/inputs/string_input_spec.rb +13 -1
  32. data/spec/localizer_spec.rb +23 -1
  33. data/spec/spec_helper.rb +2 -0
  34. data/spec/support/custom_macros.rb +5 -2
  35. data/spec/util_spec.rb +15 -22
  36. metadata +32 -32
  37. data/gemfiles/rails_3.0.gemfile +0 -7
  38. data/gemfiles/rails_3.1.gemfile +0 -7
  39. data/lib/formtastic/inputs/base/grouped_collections.rb +0 -77
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- ZTFjYzY2MDMyNWE2NGI2YzNkMzJkNTVkNTQ0ZTg2N2QxYjg0OTgwMQ==
4
+ ZWRiMTU5NmRkZjA1NTEzMDkyZTkzNjU4MjZlZjQ2M2JlNGUxNTllZg==
5
5
  data.tar.gz: !binary |-
6
- ZmE5MzZiNWU2YTUxNTEzYTgxYjhiZjhiOTkyYzY1MGRmZWE3NDZiMw==
6
+ NTMyNjFhNjhhMjQxOGRkMmFjOGZkM2YxY2EzOWU0MzhjZjc3MWE0Yg==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- ZTlhMTIxZTcxNWJhMTU5NmRkMzk2OGE2ZDBlYzQzOGZmNTQxZjE0ZTA4YTE2
10
- OTFlMWMyYTNiYTBjZmZhMTFhMjRiOTI4ZWFkYzI1MzFhMzRhOGI5ZWIwYzhk
11
- NzFlZmMwYTE3MDE2NmFmNjY1NTg2MDM4YmNhMDc1YTE4M2NlMTg=
9
+ YzIxNDg1NzU1MzdhMmMxYTAzNDhkMDgxZDUyMzNiMTZjNTE3ODc1ZWRmNjk1
10
+ NzU5NmUzZjFhZDZhOTBlZGIxNDE5N2VmOTI1MDI1ZTM0NDY3ZTY4ZDk5YTNk
11
+ YjBmNjM0OTEyNTIzZWFmNWQxZTcxZmUzMWVhMDNmZTFlMWQ5ODE=
12
12
  data.tar.gz: !binary |-
13
- OTYxODJlYjUxYWFmNDQyZDIyMjU2YjI2MWM3MzRhODEyOGY4MTE3YzliM2Q5
14
- NmVlNGQ5ZTM4MDg2ZmQyMzc1MmVkZTYzMTVhMjFkNDEwNjE3YjEzYmUzYjY3
15
- NDU1ZGZhYmRlNWZlYTcyNGE2N2RlZDMxOTY5YzMyN2QzM2VjZjE=
13
+ NmUzYWQ0Y2I5OWNhYzlmY2NlMjRjZjE5OTE1MzYwYTZmMjUxNGUwYmU2ZmEz
14
+ MWVhNTYyMTMyMDlmMDM0MTY3Zjk3NDYzMTdlOTU1YTI5Mjc2MGEzZjhjMWVm
15
+ YTVlNTBiMzJjNjIwNDBhZWI0OTY3ZmVlMjYxNzdjZGMzNDVlZWU=
@@ -3,15 +3,10 @@ before_install:
3
3
  - gem update --system
4
4
  - gem update bundler
5
5
  rvm:
6
- - 1.8.7
7
- - ree
8
- - 1.9.2
9
6
  - 1.9.3
10
7
  - 2.0.0
11
8
  - 2.1
12
9
  gemfile:
13
- - gemfiles/rails_3.0.gemfile
14
- - gemfiles/rails_3.1.gemfile
15
10
  - gemfiles/rails_3.2.gemfile
16
11
  - gemfiles/rails_4.gemfile
17
12
  - gemfiles/rails_4.0.4.gemfile
@@ -20,25 +15,6 @@ env:
20
15
  - DEFER_GC=false RAILS_EDGE=true
21
16
  script: "bundle exec rake spec"
22
17
  matrix:
23
- exclude:
24
- - rvm: 1.8.7
25
- gemfile: gemfiles/rails_4.gemfile
26
- - rvm: ree
27
- gemfile: gemfiles/rails_4.gemfile
28
- - rvm: 1.9.2
29
- gemfile: gemfiles/rails_4.gemfile
30
- - rvm: 1.8.7
31
- gemfile: gemfiles/rails_4.0.4.gemfile
32
- - rvm: ree
33
- gemfile: gemfiles/rails_4.0.4.gemfile
34
- - rvm: 1.9.2
35
- gemfile: gemfiles/rails_4.0.4.gemfile
36
- - rvm: 1.8.7
37
- gemfile: gemfiles/rails_edge.gemfile
38
- - rvm: ree
39
- gemfile: gemfiles/rails_edge.gemfile
40
- - rvm: 1.9.2
41
- gemfile: gemfiles/rails_edge.gemfile
42
18
  allow_failures:
43
19
  - rvm: 1.9.3
44
20
  gemfile: gemfiles/rails_edge.gemfile
data/Appraisals CHANGED
@@ -1,11 +1,3 @@
1
- appraise 'rails-3.0' do
2
- gem 'rails', '~> 3.0.0'
3
- end
4
-
5
- appraise 'rails-3.1' do
6
- gem 'rails', '~> 3.1.0'
7
- end
8
-
9
1
  appraise 'rails-3.2' do
10
2
  gem 'rails', '~> 3.2.0'
11
3
  end
data/CHANGELOG CHANGED
@@ -1,19 +1,3 @@
1
- 2.3.0
2
-
3
- * No changes after 2.3.0.rc4
4
-
5
- 2.3.0.rc4
6
-
7
- * Removed deprecated date, time and datetime inputs
8
- * Fixed comparison checking of boolean checked values
9
- * Fixed errors raised when handling some validations
10
- * Fixed that we weren't rendering a label on checkbox inputs when hidden_fields was set to true
11
- * Fixed eager loading in test environments
12
- * Fixed documentation to point to the new official country_select gem
13
- * Fixed that we would previously render a default wrapper id if wrapper_html[:id] was deliberately set to nil
14
- * Fixed bg with duplicate hidden fields in Rails >= 3.2.13
15
- * Note: Re-built 2.3-stable branch from 2.3.0.rc3 onwards due to accidental merges of master inside PRs
16
-
17
1
  2.3.0.rc3
18
2
 
19
3
  * Fixed invalid HTML attributes in BooleanInput with a whitelist
@@ -20,8 +20,8 @@ h2. Documentation & Support
20
20
 
21
21
  h2. Compatibility
22
22
 
23
- * Formtastic 3 (master on Github) will require Rails 3.2 minimum
24
- * Formtastic 2.3 is Rails 3 and Rails 4 compatible (Rails < 3.2 is deprecated)
23
+ * Formtastic 3 (master on Github) will require Rails 3.2.13 minimum
24
+ * Formtastic 2.3 is Rails 3 and Rails 4 compatible (Rails < 3.2.13 is deprecated)
25
25
  * Formtastic 2.1 & 2.2 is Rails 3 and Rails 4 compatible
26
26
  * Formtastic, much like Rails, is very ActiveRecord-centric. Many are successfully using other ActiveModel-like ORMs and objects (DataMapper, MongoMapper, Mongoid, Authlogic, Devise...) but we're not guaranteeing full compatibility at this stage. Patches are welcome!
27
27
 
@@ -21,21 +21,22 @@ Gem::Specification.new do |s|
21
21
  s.rdoc_options = ["--charset=UTF-8"]
22
22
  s.extra_rdoc_files = ["README.textile"]
23
23
 
24
+ s.required_ruby_version = '>= 1.9.3'
24
25
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
25
26
  s.rubygems_version = %q{1.3.6}
26
27
 
27
- s.add_dependency(%q<actionpack>, [">= 3.0"])
28
+ s.add_dependency(%q<actionpack>, [">= 3.2.13"])
28
29
 
29
30
  s.add_development_dependency(%q<nokogiri>, ["< 1.6.0"]) # 1.6 requires Ruby 1.9.2, drop in v3.0
30
- s.add_development_dependency(%q<rspec-rails>, ["~> 2.14.0"])
31
- s.add_development_dependency(%q<rspec_tag_matchers>, [">= 1.0.0"])
31
+ s.add_development_dependency(%q<rspec-rails>, ["~> 2.14"])
32
+ s.add_development_dependency(%q<rspec_tag_matchers>, ["~> 1.0"])
32
33
  s.add_development_dependency(%q<hpricot>, ["~> 0.8.3"])
33
- s.add_development_dependency(%q<BlueCloth>) # for YARD
34
+ s.add_development_dependency(%q<BlueCloth>, ["~> 1.0"]) # for YARD
34
35
  s.add_development_dependency(%q<yard>, ["~> 0.6"])
35
- s.add_development_dependency(%q<colored>)
36
- s.add_development_dependency(%q<tzinfo>)
36
+ s.add_development_dependency(%q<colored>, ["~> 1.2"])
37
+ s.add_development_dependency(%q<tzinfo>, ["~> 1.1"])
37
38
  s.add_development_dependency(%q<ammeter>, ["0.2.5"])
38
- s.add_development_dependency(%q<appraisal>, ["1.0.0.beta3"])
39
+ s.add_development_dependency(%q<appraisal>, ["~> 1.0"])
39
40
  s.add_development_dependency(%q<rake>, ["<= 10.1.1"]) # Anything higher requires Ruby 1.9, drop in v3.0
40
- s.add_development_dependency(%q<activemodel>)
41
+ s.add_development_dependency(%q<activemodel>, [">= 3.2.13"])
41
42
  end
@@ -14,10 +14,9 @@ module Formtastic
14
14
  autoload :Localizer
15
15
  autoload :Util
16
16
 
17
- # Deprecate support for Rails < 3.2
18
17
  if defined?(::Rails) && Util.deprecated_version_of_rails?
19
18
  ::ActiveSupport::Deprecation.warn(
20
- "Support for Rails < 3.2.13 will be dropped from Formtastic 3.0",
19
+ "Support for Rails < 4.0.4 will be dropped from Formtastic 4.0",
21
20
  caller)
22
21
  end
23
22
 
@@ -54,17 +54,10 @@ module Formtastic
54
54
  include Base
55
55
  include Buttonish
56
56
 
57
- # TODO absolutely horrible hack to work-around Rails < 3.1 missing button_tag, need
58
- # to figure out something more appropriate.
59
- #
60
57
  # TODO reset_action class?
61
58
  def to_html
62
59
  wrapper do
63
- if template.respond_to?(:button_tag)
64
- template.button_tag(text, button_html)
65
- else
66
- template.content_tag(:button, text, button_html)
67
- end
60
+ template.button_tag(text, button_html)
68
61
  end
69
62
  end
70
63
  end
@@ -88,6 +88,7 @@ module Formtastic
88
88
  #
89
89
  # * `:boolean` (see {Inputs::BooleanInput})
90
90
  # * `:check_boxes` (see {Inputs::CheckBoxesInput})
91
+ # * `:color` (see {Inputs::ColorInput})
91
92
  # * `:country` (see {Inputs::CountryInput})
92
93
  # * `:datetime_select` (see {Inputs::DatetimeSelectInput})
93
94
  # * `:date_select` (see {Inputs::DateSelectInput})
@@ -271,6 +272,7 @@ module Formtastic
271
272
  return :url if method.to_s =~ /^url$|^website$|_url$/
272
273
  return :phone if method.to_s =~ /(phone|fax)/
273
274
  return :search if method.to_s =~ /^search$/
275
+ return :color if method.to_s =~ /color/
274
276
  when :integer
275
277
  return :select if reflection_for(method)
276
278
  return :number
@@ -6,6 +6,7 @@ module Formtastic
6
6
  autoload :Basic
7
7
  autoload :BooleanInput
8
8
  autoload :CheckBoxesInput
9
+ autoload :ColorInput
9
10
  autoload :CountryInput
10
11
  autoload :DateInput
11
12
  autoload :DatePickerInput
@@ -11,13 +11,6 @@ module Formtastic
11
11
  @object_name = object_name
12
12
  @method = method
13
13
  @options = options.dup
14
-
15
- warn_deprecated_option!(:value, ":input_html => { :value => '...'}")
16
- warn_deprecated_option!(:hint_class, "default_hint_class configuration")
17
- warn_deprecated_option!(:error_class, "default_error_class configuration")
18
- warn_deprecated_option!(:group_by, ":collection option with a HTML string generated by Rails' grouped_options_for_select()")
19
- warn_deprecated_option!(:group_label, ":collection option with a HTML string generated by Rails' grouped_options_for_select()")
20
- warn_deprecated_option!(:find_options, "YourModel.find(...)")
21
14
  end
22
15
 
23
16
  # Usefull for deprecating options.
@@ -49,7 +42,6 @@ module Formtastic
49
42
  autoload :Database
50
43
  autoload :Errors
51
44
  autoload :Fileish
52
- autoload :GroupedCollections
53
45
  autoload :Hints
54
46
  autoload :Html
55
47
  autoload :Labelling
@@ -77,4 +69,4 @@ module Formtastic
77
69
  end
78
70
  end
79
71
  end
80
-
72
+
@@ -78,28 +78,16 @@ module Formtastic
78
78
  ) if reflection.options[:polymorphic] == true
79
79
  end
80
80
 
81
- find_options_from_options = options[:find_options] || {}
82
- conditions_from_options = find_options_from_options[:conditions] || {}
83
81
  conditions_from_reflection = (reflection.respond_to?(:options) && reflection.options[:conditions]) || {}
84
82
  conditions_from_reflection = conditions_from_reflection.call if conditions_from_reflection.is_a?(Proc)
85
83
 
86
84
  scope_conditions = conditions_from_reflection.empty? ? nil : {:conditions => conditions_from_reflection}
87
- if conditions_from_options.any?
88
- if Util.rails3?
89
- reflection.klass.scoped(scope_conditions).where(conditions_from_options)
90
- else
91
- reflection.klass.where(scope_conditions[:conditions]).where(conditions_from_options)
92
- end
85
+ where_conditions = (scope_conditions && scope_conditions[:conditions]) || {}
86
+
87
+ if Util.rails3?
88
+ reflection.klass.scoped(scope_conditions).where({}) # where is uneccessary, but keeps the stubbing simpler while we support rails3
93
89
  else
94
-
95
- if Util.rails3?
96
- find_options_from_options.merge!(:include => group_by) if self.respond_to?(:group_by) && group_by
97
- reflection.klass.scoped(scope_conditions).where(find_options_from_options)
98
- else
99
- coll = reflection.klass.where(scope_conditions)
100
- coll = coll.includes(group_by) if self.respond_to?(:group_by) && group_by
101
- coll.where(find_options_from_options)
102
- end
90
+ reflection.klass.where(where_conditions)
103
91
  end
104
92
  end
105
93
  end
@@ -8,12 +8,12 @@ module Formtastic
8
8
  end
9
9
 
10
10
  def error_sentence_html
11
- error_class = options[:error_class] || builder.default_inline_error_class
11
+ error_class = builder.default_inline_error_class
12
12
  template.content_tag(:p, Formtastic::Util.html_safe(errors.to_sentence.html_safe), :class => error_class)
13
13
  end
14
14
 
15
15
  def error_list_html
16
- error_class = options[:error_class] || builder.default_error_list_class
16
+ error_class = builder.default_error_list_class
17
17
  list_elements = []
18
18
  errors.each do |error|
19
19
  list_elements << template.content_tag(:li, Formtastic::Util.html_safe(error.html_safe))
@@ -22,7 +22,7 @@ module Formtastic
22
22
  end
23
23
 
24
24
  def error_first_html
25
- error_class = options[:error_class] || builder.default_inline_error_class
25
+ error_class = builder.default_inline_error_class
26
26
  template.content_tag(:p, Formtastic::Util.html_safe(errors.first.untaint), :class => error_class)
27
27
  end
28
28
 
@@ -8,7 +8,7 @@ module Formtastic
8
8
  template.content_tag(
9
9
  :p,
10
10
  Formtastic::Util.html_safe(hint_text),
11
- :class => (options[:hint_class] || builder.default_hint_class)
11
+ :class => builder.default_hint_class
12
12
  )
13
13
  end
14
14
  end
@@ -8,7 +8,7 @@ module Formtastic
8
8
  end
9
9
 
10
10
  def formtastic_options
11
- [:priority_countries, :priority_zones, :member_label, :member_value, :collection, :required, :label, :as, :hint, :input_html, :value_as_class, :find_options, :class]
11
+ [:priority_countries, :priority_zones, :member_label, :member_value, :collection, :required, :label, :as, :hint, :input_html, :value_as_class, :class]
12
12
  end
13
13
 
14
14
  end
@@ -102,9 +102,7 @@ module Formtastic
102
102
  value
103
103
  when NilClass
104
104
  false
105
- when Integer
106
- value == checked_value.to_i
107
- when String
105
+ when Integer, String
108
106
  value == checked_value
109
107
  when Array
110
108
  value.include?(checked_value)
@@ -0,0 +1,42 @@
1
+ module Formtastic
2
+ module Inputs
3
+
4
+ # Outputs a simple `<label>` with a HTML5 `<input type="color">` wrapped in the standard
5
+ # `<li>` wrapper. This is the default input choice for attributes with a name matching
6
+ # `/color/`, but can be applied to any text-like input with `:as => :color`.
7
+ #
8
+ # @example Full form context and output
9
+ #
10
+ # <%= semantic_form_for(@user) do |f| %>
11
+ # <%= f.inputs do %>
12
+ # <%= f.input :color, :as => :color %>
13
+ # <% end %>
14
+ # <% end %>
15
+ #
16
+ # <form...>
17
+ # <fieldset>
18
+ # <ol>
19
+ # <li class="color">
20
+ # <label for="user_color">Color</label>
21
+ # <input type="color" id="user_color" name="user[color]">
22
+ # </li>
23
+ # </ol>
24
+ # </fieldset>
25
+ # </form>
26
+ #
27
+ # @see Formtastic::Helpers::InputsHelper#input InputsHelper#input for full documentation of all possible options.
28
+ class ColorInput
29
+ include Base
30
+ include Base::Stringish
31
+ include Base::Placeholder
32
+
33
+ def to_html
34
+ raise "The :color input requires the color_field form helper, which is only available in Rails 4+" unless builder.respond_to?(:color_field)
35
+ input_wrapping do
36
+ label_html <<
37
+ builder.color_field(method, input_html_options)
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
@@ -68,7 +68,10 @@ module Formtastic
68
68
  # <%= f.input :publish_at, :as => :datetime_picker, :placeholder => "YYYY-MM-DD HH:MM" %>
69
69
  # <%= f.input :publish_at, :as => :datetime_picker, :input_html => { :placeholder => "YYYY-MM-DD HH:MM" } %>
70
70
  #
71
- # @example Using `datetime` (UTC) or `datetime-local` with `:local` (defaults to true, `datetime-local` input)
71
+ # @example Using `type=datetime-local` with `:local` option (this is the default, and recommended for browser support on iOS7 and Chrome)
72
+ # <%= f.input :publish_at, :as => :datetime_picker, :local => true %>
73
+ #
74
+ # @example Using `type=datetime` with `:local` option (not recommended)
72
75
  # <%= f.input :publish_at, :as => :datetime_picker, :local => false %>
73
76
  #
74
77
  # @see Formtastic::Helpers::InputsHelper#input InputsHelper#input for full documentation of all possible options.
@@ -31,12 +31,8 @@ module Formtastic
31
31
  class HiddenInput
32
32
  include Base
33
33
 
34
- # Override to include :value set directly from options hash. The :value set in :input_html
35
- # hash will be preferred over :value set directly in the options.
36
- #
37
- # @deprecated :value option
38
34
  def input_html_options
39
- options.slice(:value).merge(super).merge(:required => nil).merge(:autofocus => nil)
35
+ super.merge(:required => nil).merge(:autofocus => nil)
40
36
  end
41
37
 
42
38
  def to_html
@@ -63,4 +59,4 @@ module Formtastic
63
59
 
64
60
  end
65
61
  end
66
- end
62
+ end
@@ -140,22 +140,11 @@ module Formtastic
140
140
  class SelectInput
141
141
  include Base
142
142
  include Base::Collections
143
- include Base::GroupedCollections
144
143
 
145
144
  def to_html
146
145
  input_wrapping do
147
- deprecated_hidden_input <<
148
146
  label_html <<
149
- (options[:group_by] ? grouped_select_html : select_html)
150
- end
151
- end
152
-
153
- # TODO: remove from Formtastic 3.0
154
- def deprecated_hidden_input
155
- if multiple? && Util.rails3? && Util.deprecated_version_of_rails?
156
- template.hidden_field_tag(input_html_options_name_multiple, '', :id => nil)
157
- else
158
- "".html_safe
147
+ select_html
159
148
  end
160
149
  end
161
150
 
@@ -163,19 +152,6 @@ module Formtastic
163
152
  builder.select(input_name, collection, input_options, input_html_options)
164
153
  end
165
154
 
166
- def grouped_select_html
167
- builder.grouped_collection_select(
168
- input_name,
169
- grouped_collection,
170
- group_association,
171
- group_label_method,
172
- value_method,
173
- label_method,
174
- input_options,
175
- input_html_options
176
- )
177
- end
178
-
179
155
  def include_blank
180
156
  options.key?(:include_blank) ? options[:include_blank] : (single? && builder.include_blank_for_select_by_default)
181
157
  end
@@ -121,6 +121,8 @@ module Formtastic
121
121
  elsif name =~ /(.+)\[(.+)\]/
122
122
  # Rails 3 (and 3.1?) nested builder case with :post rather than @post
123
123
  [$1, $2]
124
+ elsif builder.respond_to?(:options) && builder.options.key?(:as)
125
+ [builder.options[:as].to_s]
124
126
  elsif builder.respond_to?(:options) && builder.options.key?(:parent_builder)
125
127
  # Rails 3.0 nested builder work-around case, where :parent_builder is provided by f.semantic_form_for
126
128
  [builder.options[:parent_builder].object_name.to_s, name]