Class: JqueryDatepick::InstanceTag

Inherits:
ActionView::Helpers::InstanceTag
  • Object
show all
Defined in:
lib/jquery_datepick/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

Instance Method Details

#available_datepicker_optionsObject



40
41
42
# File 'lib/jquery_datepick/form_helper.rb', line 40

def available_datepicker_options
  [:disabled, :altField, :altFormat, :appendText, :autoSize, :buttonImage, :buttonImageOnly, :buttonText, :calculateWeek, :changeMonth, :changeYear, :closeText, :constrainInput, :currentText, :dateFormat, :dayNames, :dayNamesMin, :dayNamesShort, :defaultDate, :duration, :firstDay, :gotoCurrent, :hideIfNoPrevNext, :isRTL, :maxDate, :minDate, :monthNames, :monthNamesShort, :navigationAsDateFormat, :nextText, :numberOfMonths, :prevText, :selectOtherMonths, :shortYearCutoff, :showAnim, :showButtonPanel, :showCurrentAtPos, :showMonthAfterYear, :showOn, :showOptions, :showOtherMonths, :showWeek, :stepMonths, :weekHeader, :yearRange, :yearSuffix]
end

#format_date(tb_formatted, format) ⇒ Object



49
50
51
52
# File 'lib/jquery_datepick/form_helper.rb', line 49

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)



35
36
37
38
# File 'lib/jquery_datepick/form_helper.rb', line 35

def get_name_and_id(options = {})
  add_default_name_and_id(options)
  options
end

#split_options(options) ⇒ Object



44
45
46
47
# File 'lib/jquery_datepick/form_helper.rb', line 44

def split_options(options)
  tf_options = options.slice!(*available_datepicker_options)
  return options, tf_options
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.



58
59
60
# File 'lib/jquery_datepick/form_helper.rb', line 58

def translate_format(format)
  format.gsub!(/#{FORMAT_REPLACEMENTES.keys.join("|")}/) { |match| FORMAT_REPLACEMENTES[match] }
end