Permalink
Browse files

Merge pull request #4488 from rafaelfranca/av-refactor

ActionView::Helpers::FormHelper refactoring
  • Loading branch information...
2 parents ba154bd + 6f1bf52 commit 57aaaa61977e82b9de2c43c26b00e636030685c4 @fxn fxn committed Jan 17, 2012
Showing with 688 additions and 436 deletions.
  1. +1 −3 actionpack/lib/action_view/helpers/active_model_helper.rb
  2. +3 −63 actionpack/lib/action_view/helpers/date_helper.rb
  3. +15 −302 actionpack/lib/action_view/helpers/form_helper.rb
  4. +4 −68 actionpack/lib/action_view/helpers/form_options_helper.rb
  5. +28 −0 actionpack/lib/action_view/helpers/tags.rb
  6. +134 −0 actionpack/lib/action_view/helpers/tags/base.rb
  7. +54 −0 actionpack/lib/action_view/helpers/tags/check_box.rb
  8. +16 −0 actionpack/lib/action_view/helpers/tags/checkable.rb
  9. +23 −0 actionpack/lib/action_view/helpers/tags/collection_select.rb
  10. +64 −0 actionpack/lib/action_view/helpers/tags/date_select.rb
  11. +8 −0 actionpack/lib/action_view/helpers/tags/datetime_select.rb
  12. +8 −0 actionpack/lib/action_view/helpers/tags/email_field.rb
  13. +12 −0 actionpack/lib/action_view/helpers/tags/file_field.rb
  14. +24 −0 actionpack/lib/action_view/helpers/tags/grouped_collection_select.rb
  15. +12 −0 actionpack/lib/action_view/helpers/tags/hidden_field.rb
  16. +65 −0 actionpack/lib/action_view/helpers/tags/label.rb
  17. +19 −0 actionpack/lib/action_view/helpers/tags/number_field.rb
  18. +12 −0 actionpack/lib/action_view/helpers/tags/password_field.rb
  19. +31 −0 actionpack/lib/action_view/helpers/tags/radio_button.rb
  20. +8 −0 actionpack/lib/action_view/helpers/tags/range_field.rb
  21. +24 −0 actionpack/lib/action_view/helpers/tags/search_field.rb
  22. +31 −0 actionpack/lib/action_view/helpers/tags/select.rb
  23. +8 −0 actionpack/lib/action_view/helpers/tags/tel_field.rb
  24. +20 −0 actionpack/lib/action_view/helpers/tags/text_area.rb
  25. +24 −0 actionpack/lib/action_view/helpers/tags/text_field.rb
  26. +8 −0 actionpack/lib/action_view/helpers/tags/time_select.rb
  27. +20 −0 actionpack/lib/action_view/helpers/tags/time_zone_select.rb
  28. +8 −0 actionpack/lib/action_view/helpers/tags/url_field.rb
  29. +4 −0 actionpack/test/template/form_helper_test.rb
@@ -16,9 +16,7 @@ def object
end
end
- %w(content_tag to_date_select_tag to_datetime_select_tag to_time_select_tag).each do |meth|
- module_eval "def #{meth}(*) error_wrapping(super) end", __FILE__, __LINE__
- end
+ module_eval "def content_tag(*) error_wrapping(super) end", __FILE__, __LINE__
def tag(type, options, *)
tag_generate_errors?(options) ? error_wrapping(super) : super
@@ -213,7 +213,7 @@ def time_ago_in_words(from_time, include_seconds = false)
# Note: If the day is not included as an option but the month is, the day will be set to the 1st to ensure that
# all month choices are valid.
def date_select(object_name, method, options = {}, html_options = {})
- InstanceTag.new(object_name, method, self, options.delete(:object)).to_date_select_tag(options, html_options)
+ Tags::DateSelect.new(object_name, method, self, options, html_options).render
end
# Returns a set of select tags (one for hour, minute and optionally second) pre-selected for accessing a
@@ -251,7 +251,7 @@ def date_select(object_name, method, options = {}, html_options = {})
# Note: If the day is not included as an option but the month is, the day will be set to the 1st to ensure that
# all month choices are valid.
def time_select(object_name, method, options = {}, html_options = {})
- InstanceTag.new(object_name, method, self, options.delete(:object)).to_time_select_tag(options, html_options)
+ Tags::TimeSelect.new(object_name, method, self, options, html_options).render
end
# Returns a set of select tags (one for year, month, day, hour, and minute) pre-selected for accessing a
@@ -287,7 +287,7 @@ def time_select(object_name, method, options = {}, html_options = {})
#
# The selects are prepared for multi-parameter assignment to an Active Record object.
def datetime_select(object_name, method, options = {}, html_options = {})
- InstanceTag.new(object_name, method, self, options.delete(:object)).to_datetime_select_tag(options, html_options)
+ Tags::DatetimeSelect.new(object_name, method, self, options, html_options).render
end
# Returns a set of html select-tags (one for year, month, day, hour, minute, and second) pre-selected with the
@@ -974,66 +974,6 @@ def separator(type)
end
end
- module DateHelperInstanceTag
- def to_date_select_tag(options = {}, html_options = {})
- datetime_selector(options, html_options).select_date.html_safe
- end
-
- def to_time_select_tag(options = {}, html_options = {})
- datetime_selector(options, html_options).select_time.html_safe
- end
-
- def to_datetime_select_tag(options = {}, html_options = {})
- datetime_selector(options, html_options).select_datetime.html_safe
- end
-
- private
- def datetime_selector(options, html_options)
- datetime = value(object) || default_datetime(options)
- @auto_index ||= nil
-
- options = options.dup
- options[:field_name] = @method_name
- options[:include_position] = true
- options[:prefix] ||= @object_name
- options[:index] = @auto_index if @auto_index && !options.has_key?(:index)
-
- DateTimeSelector.new(datetime, options, html_options)
- end
-
- def default_datetime(options)
- return if options[:include_blank] || options[:prompt]
-
- case options[:default]
- when nil
- Time.current
- when Date, Time
- options[:default]
- else
- default = options[:default].dup
-
- # Rename :minute and :second to :min and :sec
- default[:min] ||= default[:minute]
- default[:sec] ||= default[:second]
-
- time = Time.current
-
- [:year, :month, :day, :hour, :min, :sec].each do |key|
- default[key] ||= time.send(key)
- end
-
- Time.utc_time(
- default[:year], default[:month], default[:day],
- default[:hour], default[:min], default[:sec]
- )
- end
- end
- end
-
- class InstanceTag #:nodoc:
- include DateHelperInstanceTag
- end
-
class FormBuilder
def date_select(method, options = {}, html_options = {})
@template.date_select(@object_name, method, objectify_options(options), html_options)
Oops, something went wrong.

0 comments on commit 57aaaa6

Please sign in to comment.