Permalink
Browse files

Don't namespace IntanceTag.

  • Loading branch information...
1 parent 85be357 commit b29556d376cab137691a03c55fddb8a8f742dd76 brianjlandau committed Oct 1, 2008
Showing with 63 additions and 63 deletions.
  1. +0 −1 init.rb
  2. +63 −61 lib/unobtrusive_date_picker.rb
  3. +0 −1 spec/spec_helper.rb
View
@@ -6,4 +6,3 @@
ActionView::Helpers::DateHelper.send :include, UnobtrusiveDatePicker::UnobtrusiveDatePickerHelper
ActionView::Base.send :include, UnobtrusiveDatePicker::AssetTagHelper
ActionView::Helpers::AssetTagHelper.send :include, UnobtrusiveDatePicker::AssetTagHelper
-ActionView::Helpers::InstanceTag.send :include, UnobtrusiveDatePicker::InstanceTag
@@ -361,83 +361,86 @@ def unobtrusive_datepicker_includes(options = {})
end
end
- module InstanceTag # :nodoc: all
- include UnobtrusiveDatePicker::UnobtrusiveDatePickerHelper
+end
+# /UnobtrusiveDatePicker
- def to_datepicker_datetime_select_tag(options = {}, html_options = {})
- datepicker_select(options, true, html_options)
- end
+module ActionView # :nodoc: all
+ module Helpers
+ class InstanceTag
+ include UnobtrusiveDatePicker::UnobtrusiveDatePickerHelper
- def to_datepicker_date_select_tag(options = {}, html_options = {})
- datepicker_select(options, false, html_options)
- end
-
- def to_datepicker_text_tag(options = {}, html_options = {})
- options, html_options = datepicker_text_field_options(options, html_options)
- html_options[:value] = format_date_value_for_text_field(options[:format], options[:divider], value(object))
- to_input_field_tag('text', html_options)
- end
+ def to_datepicker_datetime_select_tag(options = {}, html_options = {})
+ datepicker_select(options, true, html_options)
+ end
- private
+ def to_datepicker_date_select_tag(options = {}, html_options = {})
+ datepicker_select(options, false, html_options)
+ end
+
+ def to_datepicker_text_tag(options = {}, html_options = {})
+ options, html_options = datepicker_text_field_options(options, html_options)
+ html_options[:value] = format_date_value_for_text_field(options[:format], options[:divider], value(object))
+ to_input_field_tag('text', html_options)
+ end
- def datepicker_select(options, time, html_options = {})
- defaults = { :discard_type => true }
- options = defaults.merge(options)
+ private
- datetime = value(object)
- datetime ||= Time.now unless options[:include_blank]
+ def datepicker_select(options, time, html_options = {})
+ defaults = { :discard_type => true }
+ options = defaults.merge(options)
- position = { :year => 1, :month => 2, :day => 3, :hour => 4, :minute => 5, :ampm => 6 }
- order = (options[:order] ||= [:day, :month, :year])
+ datetime = value(object)
+ datetime ||= Time.now unless options[:include_blank]
- # Maintain valid dates by including hidden fields for discarded elements
- [:day, :month, :year].each { |o| order.unshift(o) unless order.include?(o) }
+ position = { :year => 1, :month => 2, :day => 3, :hour => 4, :minute => 5, :ampm => 6 }
+ order = (options[:order] ||= [:day, :month, :year])
- # Ensure proper ordering of :hour, :minute and :second
- if time
- [:hour, :minute, :ampm].each { |o| order.delete(o); order.push(o) }
- end
+ # Maintain valid dates by including hidden fields for discarded elements
+ [:day, :month, :year].each { |o| order.unshift(o) unless order.include?(o) }
- date_or_time_select = ''
- order.reverse.each do |param|
- if param == :ampm
- date_or_time_select.insert(0, self.send("datepicker_select_#{param}", datetime, datepicker_options_with_prefix(position[param], options.merge(:string => true)), html_options))
- else
- date_or_time_select.insert(0, self.send("datepicker_select_#{param}", datetime, datepicker_options_with_prefix(position[param], options), html_options))
+ # Ensure proper ordering of :hour, :minute and :second
+ if time
+ [:hour, :minute, :ampm].each { |o| order.delete(o); order.push(o) }
end
- date_or_time_select.insert(0,
- case param
- when :hour then "   "
- when :minute then " : "
- else ""
- end
- )
- end
- date_or_time_select
- end
+ date_or_time_select = ''
+ order.reverse.each do |param|
+ if param == :ampm
+ date_or_time_select.insert(0, self.send("datepicker_select_#{param}", datetime, datepicker_options_with_prefix(position[param], options.merge(:string => true)), html_options))
+ else
+ date_or_time_select.insert(0, self.send("datepicker_select_#{param}", datetime, datepicker_options_with_prefix(position[param], options), html_options))
+ end
+ date_or_time_select.insert(0,
+ case param
+ when :hour then "   "
+ when :minute then " : "
+ else ""
+ end
+ )
+ end
- def datepicker_options_with_prefix(position, options)
- prefix = "#{@object_name}"
- if options[:index]
- prefix << "[#{options[:index]}]"
- elsif @auto_index
- prefix << "[#{@auto_index}]"
+ date_or_time_select
end
- options[:id_prefix] = "#{@object_name}_#{@method_name}"
- if options[:string]
- options[:name] = "#{prefix}[#{@method_name}(#{position}s)]"
- options.merge(:prefix => "#{prefix}[#{@method_name}(#{position}s)]")
- else
- options[:name] = "#{prefix}[#{@method_name}(#{position}i)]"
- options.merge(:prefix => "#{prefix}[#{@method_name}(#{position}i)]")
+
+ def datepicker_options_with_prefix(position, options)
+ prefix = "#{@object_name}"
+ if options[:index]
+ prefix << "[#{options[:index]}]"
+ elsif @auto_index
+ prefix << "[#{@auto_index}]"
+ end
+ options[:id_prefix] = "#{@object_name}_#{@method_name}"
+ if options[:string]
+ options[:name] = "#{prefix}[#{@method_name}(#{position}s)]"
+ options.merge(:prefix => "#{prefix}[#{@method_name}(#{position}s)]")
+ else
+ options[:name] = "#{prefix}[#{@method_name}(#{position}i)]"
+ options.merge(:prefix => "#{prefix}[#{@method_name}(#{position}i)]")
+ end
end
end
-
end
-
end
-# /UnobtrusiveDatePicker
module ActionView::Helpers::PrototypeHelper # :nodoc: all
class JavaScriptGenerator
@@ -471,4 +474,3 @@ def unobtrusive_datetime_picker(method, options = {}, html_options = {})
end
end
end
-
View
@@ -14,7 +14,6 @@
ActionView::Helpers::DateHelper.send :include, UnobtrusiveDatePicker::UnobtrusiveDatePickerHelper
ActionView::Base.send :include, UnobtrusiveDatePicker::AssetTagHelper
ActionView::Helpers::AssetTagHelper.send :include, UnobtrusiveDatePicker::AssetTagHelper
-ActionView::Helpers::InstanceTag.send :include, UnobtrusiveDatePicker::InstanceTag
ActionController::Base.perform_caching = false
ActionController::Base.consider_all_requests_local = true

0 comments on commit b29556d

Please sign in to comment.