Module: Formtastic::Inputs::Base::Timeish
- Included in:
- DateInput, DatetimeInput, TimeInput
- Defined in:
- lib/formtastic/inputs/base/timeish.rb
Instance Method Summary collapse
- #date_fragments ⇒ Object
- #default_date_fragments ⇒ Object
- #fragment_id(fragment) ⇒ Object
- #fragment_input_html(fragment) ⇒ Object
- #fragment_label(fragment) ⇒ Object
- #fragment_label_html(fragment) ⇒ Object
- #fragment_name(fragment) ⇒ Object
- #fragment_wrapping(&block) ⇒ Object
- #fragments ⇒ Object
- #fragments_inner_wrapping(&block) ⇒ Object
- #fragments_label ⇒ Object
- #fragments_wrapping(&block) ⇒ Object
- #fragments_wrapping_html_options ⇒ Object
- #i18n_date_fragments ⇒ Object
-
#include_blank? ⇒ Boolean
TODO extract to BlankOptions or similar – Select uses similar code.
- #position(fragment) ⇒ Object
- #positions ⇒ Object
- #time_fragments ⇒ Object
- #to_html ⇒ Object
- #value ⇒ Object
Instance Method Details
#date_fragments ⇒ Object
32 33 34 |
# File 'lib/formtastic/inputs/base/timeish.rb', line 32 def date_fragments [:order] || i18n_date_fragments || default_date_fragments end |
#default_date_fragments ⇒ Object
36 37 38 |
# File 'lib/formtastic/inputs/base/timeish.rb', line 36 def default_date_fragments [:year, :month, :day] end |
#fragment_id(fragment) ⇒ Object
53 54 55 |
# File 'lib/formtastic/inputs/base/timeish.rb', line 53 def fragment_id(fragment) "#{[:id]}_#{position(fragment)}i" end |
#fragment_input_html(fragment) ⇒ Object
70 71 72 73 |
# File 'lib/formtastic/inputs/base/timeish.rb', line 70 def fragment_input_html(fragment) opts = .merge(:prefix => object_name, :field_name => fragment_name(fragment), :default => value, :include_blank => include_blank?) template.send(:"select_#{fragment}", value, opts, .merge(:id => fragment_id(fragment))) end |
#fragment_label(fragment) ⇒ Object
44 45 46 47 48 49 50 51 |
# File 'lib/formtastic/inputs/base/timeish.rb', line 44 def fragment_label(fragment) = [:labels] || {} if .key?(fragment) [fragment] else ::I18n.t(fragment.to_s, :default => fragment.to_s.humanize, :scope => [:datetime, :prompts]) end end |
#fragment_label_html(fragment) ⇒ Object
61 62 63 64 |
# File 'lib/formtastic/inputs/base/timeish.rb', line 61 def fragment_label_html(fragment) text = fragment_label(fragment) text.blank? ? "" : template.content_tag(:label, text, :for => fragment_id(fragment)) end |
#fragment_name(fragment) ⇒ Object
57 58 59 |
# File 'lib/formtastic/inputs/base/timeish.rb', line 57 def fragment_name(fragment) "#{method}(#{position(fragment)}i)" end |
#fragment_wrapping(&block) ⇒ Object
40 41 42 |
# File 'lib/formtastic/inputs/base/timeish.rb', line 40 def fragment_wrapping(&block) template.content_tag(:li, template.capture(&block)) end |
#fragments ⇒ Object
24 25 26 |
# File 'lib/formtastic/inputs/base/timeish.rb', line 24 def fragments date_fragments + time_fragments end |
#fragments_inner_wrapping(&block) ⇒ Object
116 117 118 119 120 |
# File 'lib/formtastic/inputs/base/timeish.rb', line 116 def fragments_inner_wrapping(&block) template.content_tag(:ol, template.capture(&block) ) end |
#fragments_label ⇒ Object
105 106 107 108 109 110 111 112 113 114 |
# File 'lib/formtastic/inputs/base/timeish.rb', line 105 def fragments_label if render_label? template.content_tag(:legend, builder.label(method, :for => "#{[:id]}_1i"), :class => "label" ) else "" end end |
#fragments_wrapping(&block) ⇒ Object
94 95 96 97 98 99 |
# File 'lib/formtastic/inputs/base/timeish.rb', line 94 def fragments_wrapping(&block) template.content_tag(:fieldset, template.capture(&block).html_safe, ) end |
#fragments_wrapping_html_options ⇒ Object
101 102 103 |
# File 'lib/formtastic/inputs/base/timeish.rb', line 101 def {} end |
#i18n_date_fragments ⇒ Object
88 89 90 91 92 |
# File 'lib/formtastic/inputs/base/timeish.rb', line 88 def i18n_date_fragments order = ::I18n.t(:order, :scope => [:date]) order = nil unless order.is_a?(Array) order end |
#include_blank? ⇒ Boolean
TODO extract to BlankOptions or similar – Select uses similar code
76 77 78 |
# File 'lib/formtastic/inputs/base/timeish.rb', line 76 def include_blank? .key?(:include_blank) ? [:include_blank] : builder.include_blank_for_select_by_default end |
#position(fragment) ⇒ Object
84 85 86 |
# File 'lib/formtastic/inputs/base/timeish.rb', line 84 def position(fragment) positions[fragment] end |
#positions ⇒ Object
80 81 82 |
# File 'lib/formtastic/inputs/base/timeish.rb', line 80 def positions { :year => 1, :month => 2, :day => 3, :hour => 4, :minute => 5, :second => 6 } end |
#time_fragments ⇒ Object
28 29 30 |
# File 'lib/formtastic/inputs/base/timeish.rb', line 28 def time_fragments [:include_seconds] ? [:hour, :minute, :second] : [:hour, :minute] end |
#to_html ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/formtastic/inputs/base/timeish.rb', line 6 def to_html input_wrapping do fragments_wrapping do fragments_label << template.content_tag(:fieldset, template.content_tag(:ol, fragments.map do |fragment| fragment_wrapping do fragment_label_html(fragment) << fragment_input_html(fragment) end end.join.html_safe # TODO is this safe? ) ) end end end |
#value ⇒ Object
66 67 68 |
# File 'lib/formtastic/inputs/base/timeish.rb', line 66 def value object.send(method) if object && object.respond_to?(method) end |