countries 0.9.2 → 0.9.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/.rvmrc DELETED
@@ -1 +0,0 @@
1
- rvm use ruby-1.9.3@countries --create
@@ -1,53 +0,0 @@
1
- # CountrySelect - stolen from http://github.com/rails/iso-3166-country-select
2
- module ActionView
3
- module Helpers
4
- module FormOptionsHelper
5
-
6
- def country_select(object, method, priority_countries = nil, options = {}, html_options = {})
7
- InstanceTag.new(object, method, self, options.delete(:object)).to_country_select_tag(priority_countries, options, html_options)
8
- end
9
-
10
- def country_options_for_select(selected_country_code = nil, priority_countries = nil)
11
- country_options = ""
12
-
13
- if priority_countries
14
- priority_countries = [*priority_countries].map { |x| [x,ISO3166::Country::NameIndex[x]] }
15
- country_options += options_for_select(priority_countries, selected_country_code)
16
- country_options += "<option value=\"\" disabled=\"disabled\">-------------</option>\n"
17
-
18
- # prevent selected_country_code from being included twice in the HTML which causes
19
- # some browsers to select the second selected option (not priority)
20
- # which makes it harder to select an alternative priority country
21
- if selected_country = ISO3166::Country[selected_country_code]
22
- selected_country_code = nil if priority_countries.include?([selected_country.name, selected_country_code])
23
- end
24
- end
25
-
26
- country_options = country_options.html_safe if country_options.respond_to?(:html_safe)
27
- countries = ISO3166::Country::Names.map{ |(name,alpha2)| [name.html_safe,alpha2] }
28
-
29
- country_options + options_for_select(countries, selected_country_code)
30
- end
31
- end
32
-
33
- class InstanceTag
34
- def to_country_select_tag(priority_countries, options, html_options)
35
- html_options = html_options.stringify_keys
36
- add_default_name_and_id(html_options)
37
- value = options.delete(:selected) || value(object)
38
- content_tag("select",
39
- add_options(
40
- country_options_for_select(value, priority_countries),
41
- options, value
42
- ), html_options
43
- )
44
- end
45
- end
46
-
47
- class FormBuilder
48
- def country_select(method, priority_countries = nil, options = {}, html_options = {})
49
- @template.country_select(@object_name, method, priority_countries, options.merge(:object => @object), html_options)
50
- end
51
- end
52
- end
53
- end