Module: I18nCountrySelect::InstanceTag
- Defined in:
- lib/i18n_country_select/instance_tag.rb
Instance Method Summary collapse
-
#country_code_select(priority_countries, options, html_options) ⇒ Object
Adapted from Rails country_select.
- #country_translations ⇒ Object
- #to_country_code_select_tag(priority_countries, html_options = {}, options = {}) ⇒ Object
Instance Method Details
#country_code_select(priority_countries, options, html_options) ⇒ Object
Adapted from Rails country_select. Just uses country codes instead of full names.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/i18n_country_select/instance_tag.rb', line 12 def country_code_select(priority_countries, , ) selected = .fetch(:selected, object.respond_to?(@method_name) ? object.send(@method_name) : nil) countries = "" if .present? and [:include_blank] option = [:include_blank] == true ? "" : [:include_blank] countries += "<option>#{option}</option>\n" end if priority_countries countries += (priority_countries, selected) countries += "<option value=\"\" disabled=\"disabled\">-------------</option>\n" end translations = if [:exclude].present? country_translations.reject { |ct| [:exclude].include? ct[1] } else country_translations end countries = countries + (translations, selected) = .stringify_keys add_default_name_and_id() content_tag(:select, countries.html_safe, ) end |
#country_translations ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/i18n_country_select/instance_tag.rb', line 41 def country_translations Thread.current[:country_translations] ||= {} Thread.current[:country_translations][I18n.locale] ||= begin (I18n.t 'countries').keys.map do |code| translation = I18n.t(code, :scope => :countries, :default => 'missing') translation == 'missing' ? nil : [translation, code] end.compact.sort_by do |translation, code| normalize_translation(translation) end end end |
#to_country_code_select_tag(priority_countries, html_options = {}, options = {}) ⇒ Object
3 4 5 6 7 8 9 |
# File 'lib/i18n_country_select/instance_tag.rb', line 3 def to_country_code_select_tag(priority_countries, = {}, = {}) # Rails 4 stores options sent when creating an InstanceTag. # Let's use them! = @options if defined?(@options) country_code_select(priority_countries, , ) end |