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.
- checksums.yaml +15 -0
- data/.gitignore +3 -0
- data/.travis.yml +3 -0
- data/Gemfile +0 -1
- data/README.markdown +65 -17
- data/countries.gemspec +1 -1
- data/lib/countries.rb +4 -0
- data/lib/countries/country.rb +52 -31
- data/lib/countries/mongoid.rb +42 -0
- data/lib/countries/version.rb +1 -1
- data/lib/data/countries.yaml +7366 -4817
- data/lib/data/subdivisions/BQ.yaml +10 -0
- data/lib/data/subdivisions/CL.yaml +6 -0
- data/lib/data/subdivisions/HU.yaml +69 -0
- data/lib/data/subdivisions/IT.yaml +9 -0
- data/lib/data/subdivisions/MA.yaml +33 -0
- data/lib/data/subdivisions/MH.yaml +4 -0
- data/lib/data/subdivisions/MT.yaml +287 -0
- data/lib/data/subdivisions/TH.yaml +1 -2
- data/lib/data/subdivisions/UG.yaml +96 -0
- data/lib/data/subdivisions/US.yaml +9 -0
- data/lib/iso3166.rb +4 -1
- data/spec/country_spec.rb +68 -10
- data/spec/mongoid_spec.rb +67 -0
- metadata +15 -19
- data/.rvmrc +0 -1
- data/lib/countries/select_helper.rb +0 -53
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
|