Module: ActionView::Helpers::FormOptionsHelper

Defined in:
lib/i18n_plus/state.rb,
lib/i18n_plus/locale.rb,
lib/i18n_plus/country.rb,
lib/i18n_plus/currency.rb,
lib/i18n_plus/language.rb

Instance Method Summary collapse

Instance Method Details

#country_options_for_select(selected = nil, *priority_country_codes) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/i18n_plus/country.rb', line 33

def country_options_for_select(selected = nil, *priority_country_codes)
  html = "".html_safe
  unless priority_country_codes.empty?
    priority_countries = priority_country_codes.map { |code| [I18nPlus.country_name(code), code] }
    unless priority_countries.empty?
      html += options_for_select(priority_countries, selected)
      html += "<option value=\"\" disabled=\"disabled\">----------</option>".html_safe
    end
  end
  all_countries = I18nPlus.countries.map { |code,name| [name, code] }.sort
  return html + options_for_select(all_countries, priority_country_codes.include?(selected) ? nil : selected)
end

#country_select(object, method, priority_country_codes = nil, options = {}, html_options = {}) ⇒ Object



23
24
25
26
27
28
29
30
31
# File 'lib/i18n_plus/country.rb', line 23

def country_select(object, method, priority_country_codes = nil, options = {}, html_options = {})
  tag = if defined?(ActionView::Helpers::InstanceTag) &&
        ActionView::Helpers::InstanceTag.instance_method(:initialize).arity != 0
    InstanceTag.new(object, method, self, options.delete(:object))
  else
    CountrySelect.new(object, method, self, options)
  end
  tag.to_country_select_tag(priority_country_codes, options, html_options)
end

#currency_options_for_select(selected = nil, *priority_currency_codes) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/i18n_plus/currency.rb', line 33

def currency_options_for_select(selected = nil, *priority_currency_codes)
  html = "".html_safe
  unless priority_currency_codes.empty?
    priority_currencies = priority_currency_codes.map { |code| [I18nPlus.currency_name(code), code] }
    unless priority_currencies.empty?
      html += options_for_select(priority_currencies, selected)
      html += "<option value=\"\" disabled=\"disabled\">----------</option>".html_safe
    end
  end
  all_currencies = I18nPlus.currencies.map { |code,name| [name, code] }.sort
  return html + options_for_select(all_currencies, priority_currency_codes.include?(selected) ? nil : selected)
end

#currency_select(object, method, priority_currency_codes = nil, options = {}, html_options = {}) ⇒ Object



23
24
25
26
27
28
29
30
31
# File 'lib/i18n_plus/currency.rb', line 23

def currency_select(object, method, priority_currency_codes = nil, options = {}, html_options = {})
  tag = if defined?(ActionView::Helpers::InstanceTag) &&
        ActionView::Helpers::InstanceTag.instance_method(:initialize).arity != 0
    InstanceTag.new(object, method, self, options.delete(:object))
  else
    CurrencySelect.new(object, method, self, options)
  end
  tag.to_currency_select_tag(priority_currency_codes, options, html_options)
end

#language_options_for_select(selected = nil, *priority_language_codes) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/i18n_plus/language.rb', line 34

def language_options_for_select(selected = nil, *priority_language_codes)
  html = "".html_safe
  unless priority_language_codes.empty?
    priority_languages = priority_language_codes.map { |code| [I18nPlus.language_name(code), code] }
    unless priority_languages.empty?
      html += options_for_select(priority_languages, selected)
      html += "<option value=\"\" disabled=\"disabled\">----------</option>".html_safe
    end
  end
  all_languages = I18nPlus.languages.map { |code,name| [name, code] }.sort
  return html + options_for_select(all_languages, priority_language_codes.include?(selected) ? nil : selected)
end

#language_select(object, method, priority_language_codes = nil, options = {}, html_options = {}) ⇒ Object



23
24
25
26
27
28
29
30
31
32
# File 'lib/i18n_plus/language.rb', line 23

def language_select(object, method, priority_language_codes = nil, options = {}, html_options = {})
  tag = if defined?(ActionView::Helpers::InstanceTag) &&
        ActionView::Helpers::InstanceTag.instance_method(:initialize).arity != 0
    InstanceTag.new(object, method, self, options.delete(:object))
  else
    LanguageSelect.new(object, method, self, options)
  end

  tag.to_language_select_tag(priority_language_codes, options, html_options)
end

#locale_options_for_select(selected = nil, *priority_locale_codes) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/i18n_plus/locale.rb', line 33

def locale_options_for_select(selected = nil, *priority_locale_codes)
  html = "".html_safe
  unless priority_locale_codes.empty?
    priority_locales = priority_locale_codes.map { |code| [I18nPlus.locale_name(code), code] }
    unless priority_locales.empty?
      html += options_for_select(priority_locales, selected)
      html += "<option value=\"\" disabled=\"disabled\">----------</option>".html_safe
    end
  end
  all_locales = I18nPlus.locales.map { |code,name| [name, code] }.sort
  return html + options_for_select(all_locales, priority_locale_codes.include?(selected) ? nil : selected)
end

#locale_select(object, method, priority_locale_codes = nil, options = {}, html_options = {}) ⇒ Object



23
24
25
26
27
28
29
30
31
# File 'lib/i18n_plus/locale.rb', line 23

def locale_select(object, method, priority_locale_codes = nil, options = {}, html_options = {})
  tag = if defined?(ActionView::Helpers::InstanceTag) &&
        ActionView::Helpers::InstanceTag.instance_method(:initialize).arity != 0
    InstanceTag.new(object, method, self, options.delete(:object))
  else
    LocaleSelect.new(object, method, self, options)
  end
  tag.to_locale_select_tag(priority_locale_codes, options, html_options)
end

#state_options_for_select(country_code, selected = nil) ⇒ Object



33
34
35
36
37
# File 'lib/i18n_plus/state.rb', line 33

def state_options_for_select(country_code, selected = nil)
  collection = I18nPlus.states(country_code)
  options = collection.map { |code,name| [name, code] }.sort
  options_for_select(options, selected)
end

#state_select(object, method, country_code, options = {}, html_options = {}) ⇒ Object



23
24
25
26
27
28
29
30
31
# File 'lib/i18n_plus/state.rb', line 23

def state_select(object, method, country_code, options = {}, html_options = {})
  tag = if defined?(ActionView::Helpers::InstanceTag) &&
        ActionView::Helpers::InstanceTag.instance_method(:initialize).arity != 0
    InstanceTag.new(object, method, self, options.delete(:object))
  else
    StateSelect.new(object, method, self, options)
  end
  tag.to_state_select_tag(country_code, options, html_options)
end