Class: BootstrapDatepicker::InstanceTag
- Inherits:
-
ActionView::Helpers::InstanceTag
- Object
- ActionView::Helpers::InstanceTag
- BootstrapDatepicker::InstanceTag
- Defined in:
- lib/app/helpers/form_helper.rb
Constant Summary collapse
- FORMAT_REPLACEMENTES =
{ "yy" => "%Y", "mm" => "%m", "dd" => "%d", "d" => "%-d", "m" => "%-m", "y" => "%y", "M" => "%b"}
Instance Method Summary collapse
- #available_datepicker_options ⇒ Object
- #available_html_attributes ⇒ Object
- #baked_options(options) ⇒ Object
- #format_date(tb_formatted, format) ⇒ Object
-
#get_name_and_id(options = {}) ⇒ Object
Extending ActionView::Helpers::InstanceTag module to make Rails build the name and id Just returns the options before generate the HTML in order to use the same id and name (see to_input_field_tag mehtod).
-
#translate_format(format) ⇒ Object
Method that translates the datepicker date formats, defined in (docs.jquery.com/UI/Datepicker/formatDate) to the ruby standard format (www.ruby-doc.org/core-1.9.3/Time.html#method-i-strftime).
Instance Method Details
#available_datepicker_options ⇒ Object
45 46 47 |
# File 'lib/app/helpers/form_helper.rb', line 45 def [:format, :week_start, :view_mode, :min_view_mode] end |
#available_html_attributes ⇒ Object
49 50 51 |
# File 'lib/app/helpers/form_helper.rb', line 49 def available_html_attributes [:class, :value, :maxlength] end |
#baked_options(options) ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/app/helpers/form_helper.rb', line 53 def () = Hash.new .each do |key, value| if .include? key new_key = ("data-" << key.to_s) [new_key] = value end if available_html_attributes.include? key [key.to_s] = value end end puts 'options' puts puts 'tf_options' puts return , end |
#format_date(tb_formatted, format) ⇒ Object
77 78 79 80 |
# File 'lib/app/helpers/form_helper.rb', line 77 def format_date(tb_formatted, format) new_format = translate_format(format) Date.parse(tb_formatted).strftime(new_format) end |
#get_name_and_id(options = {}) ⇒ Object
Extending ActionView::Helpers::InstanceTag module to make Rails build the name and id Just returns the options before generate the HTML in order to use the same id and name (see to_input_field_tag mehtod)
40 41 42 43 |
# File 'lib/app/helpers/form_helper.rb', line 40 def get_name_and_id( = {}) add_default_name_and_id() end |
#translate_format(format) ⇒ Object
Method that translates the datepicker date formats, defined in (docs.jquery.com/UI/Datepicker/formatDate) to the ruby standard format (www.ruby-doc.org/core-1.9.3/Time.html#method-i-strftime). This gem is not going to support all the options, just the most used.
86 87 88 |
# File 'lib/app/helpers/form_helper.rb', line 86 def translate_format(format) format.gsub!(/#{FORMAT_REPLACEMENTES.keys.join("|")}/) { |match| FORMAT_REPLACEMENTES[match] } end |