localized_country_select 0.9.8 → 0.10.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 7ff1f5a996b282ec7a2493368727792702c0e4b48b8cdc0dcff579a726e42c1e
4
+ data.tar.gz: 8a7ca054c3d89883d6d683929ef7414065daf0be6c08a6a0f43bef38c818ebf9
5
+ SHA512:
6
+ metadata.gz: ae940269acba150b3316fd38d775e9aa008562c74e55cbc704469acb14d3f3f4e16f0807a55582e5bc59a40b6fbd3336a0a2657d3cfd60a1eb7585efd0f512ad
7
+ data.tar.gz: b91d5323de3696d3d449c515dc14795a87ceeb479b83a02b572d20aeb72c401c2ef58ddf6feeacae6349636c27641b3e2e222c05c712d84c220ba0d77959441b
data/.gitignore CHANGED
@@ -1,3 +1,4 @@
1
1
  .DS_Store
2
2
  */.DS_Store
3
- rdoc
3
+ rdoc
4
+ *.gem
@@ -11,18 +11,24 @@ You can easily translate country codes in your application like this:
11
11
 
12
12
  <%= I18n.t @user.country, :scope => 'countries' %>
13
13
 
14
- Comes with a Rake task <tt>rake import:country_select LOCALE=de</tt> for importing country names
14
+ Comes with a Rake task <tt>rails import:country_select LOCALE=de</tt> for importing country names
15
15
  from Unicode.org's CLDR repository (http://www.unicode.org/cldr/data/charts/summary/root.html)
16
16
  Don't forget to restart the application when you add new locale.
17
17
 
18
18
  ActionView helper code is adapted from Rails' default +country_select+ plugin (previously in core).
19
19
  See http://github.com/rails/country_select/tree/master/lib/country_select.rb
20
20
 
21
+ == Rails 5 / Rails 6
22
+
23
+ In your Gemfile add:
24
+
25
+ gem 'localized_country_select', '~> 0.10.0'
26
+
21
27
  == Rails 3 / Rails 4
22
28
 
23
29
  In your Gemfile add:
24
30
 
25
- gem 'localized_country_select', '>= 0.9.8'
31
+ gem 'localized_country_select', '= 0.9.11'
26
32
 
27
33
  == Rails 2.3
28
34
 
@@ -35,7 +41,7 @@ In environment.rb add
35
41
 
36
42
  Show full country names:
37
43
 
38
- <%= localized_country_select(:user, :country, [], {:include_blank => 'Please choose...'}) %>
44
+ <%= localized_country_select(:user, :country, [], {include_blank: 'Please choose...'}) %>
39
45
 
40
46
  will become:
41
47
 
@@ -50,7 +56,7 @@ will become:
50
56
 
51
57
  Show only country codes:
52
58
 
53
- <%= localized_country_select(:user, :country, [], {:include_blank => 'Please choose...', :description => :abbreviated}) %>
59
+ <%= localized_country_select(:user, :country, [], {include_blank: 'Please choose...', description: :abbreviated}) %>
54
60
 
55
61
  will become:
56
62
 
@@ -68,7 +74,7 @@ for the en locale.
68
74
 
69
75
  You can exclude countries by code using the exclude option (a single code or an array of country codes):
70
76
 
71
- localized_country_select(:user, :country, [], {:exclude => [:ZZ, :US]})
77
+ localized_country_select(:user, :country, [], {exclude: [:ZZ, :US]})
72
78
 
73
79
 
74
80
  == Formtastic and SimpleForm
@@ -26,7 +26,7 @@ module LocalizedCountrySelect
26
26
  def localized_countries_array(options={})
27
27
  exclude = Array(options[:exclude]).map {|code| code.to_s.upcase }
28
28
 
29
- if(options[:description]==:abbreviated)
29
+ if(options[:description] == :abbreviated)
30
30
  I18n.translate(:countries).map { |key, value| [key.to_s.upcase] if !exclude.include?(key.to_s.upcase) }
31
31
  else
32
32
  I18n.translate(:countries).map { |key, value| [value, key.to_s.upcase] if !exclude.include?(key.to_s.upcase) }
@@ -36,8 +36,8 @@ module LocalizedCountrySelect
36
36
  # == Example
37
37
  # priority_countries_array([:TW, :CN])
38
38
  # # => [ ['Taiwan', 'TW'], ['China', 'CN'] ]
39
- def priority_countries_array(country_codes=[],options={})
40
- if(options[:description]==:abbreviated)
39
+ def priority_countries_array(country_codes=[], options={})
40
+ if(options[:description] == :abbreviated)
41
41
  country_codes.map { |code| [code.to_s.upcase] }
42
42
  else
43
43
  countries = I18n.translate(:countries)
@@ -57,13 +57,7 @@ module ActionView
57
57
  # Country codes listed as an array of symbols in +priority_countries+ argument will be listed first
58
58
  # TODO : Implement pseudo-named args with a hash, not the "somebody said PHP?" multiple args sillines
59
59
  def localized_country_select(object, method, priority_countries = nil, options = {}, html_options = {})
60
- tag = if defined?(ActionView::Helpers::InstanceTag) &&
61
- ActionView::Helpers::InstanceTag.instance_method(:initialize).arity != 0
62
-
63
- InstanceTag.new(object, method, self, options.delete(:object))
64
- else
65
- CountrySelect.new(object, method, self, options)
66
- end
60
+ tag = CountrySelect.new(object, method, self, options)
67
61
 
68
62
  tag.to_localized_country_select_tag(priority_countries, options, html_options)
69
63
  end
@@ -99,7 +93,6 @@ module ActionView
99
93
  def to_localized_country_select_tag(priority_countries, options, html_options)
100
94
  html_options = html_options.stringify_keys
101
95
  add_default_name_and_id(html_options)
102
- value = value(object)
103
96
  content_tag("select",
104
97
  add_options(
105
98
  localized_country_options_for_select(value, priority_countries, options).html_safe,
@@ -109,20 +102,13 @@ module ActionView
109
102
  end
110
103
  end
111
104
 
112
- if defined?(ActionView::Helpers::InstanceTag) &&
113
- ActionView::Helpers::InstanceTag.instance_method(:initialize).arity != 0
114
- class InstanceTag
115
- include ToCountrySelectTag
116
- end
117
- else
118
- class CountrySelect < Tags::Base
119
- include ToCountrySelectTag
120
- end
105
+ class CountrySelect < Tags::Base
106
+ include ToCountrySelectTag
121
107
  end
122
108
 
123
109
  class FormBuilder
124
110
  def localized_country_select(method, priority_countries = nil, options = {}, html_options = {})
125
- @template.localized_country_select(@object_name, method, priority_countries, options.merge(:object => @object), html_options)
111
+ @template.localized_country_select(@object_name, method, priority_countries, options.merge(object: @object), html_options)
126
112
  end
127
113
  alias_method :country_select, :localized_country_select
128
114
  end
@@ -1,3 +1,3 @@
1
1
  module LocalizedCountrySelect
2
- VERSION = "0.9.8"
2
+ VERSION = '0.10.1'
3
3
  end
@@ -1,9 +1,10 @@
1
1
  require 'rubygems'
2
2
  require 'open-uri'
3
3
  require 'active_support/inflector'
4
+ require 'csv'
4
5
 
5
6
  # Rake task for importing country names from Unicode.org's CLDR repository
6
- # (http://www.unicode.org/cldr/data/charts/summary/root.html).
7
+ # (https://unicode-org.github.io/cldr-staging/charts/37/summary/root.html).
7
8
  #
8
9
  # It parses a HTML file from Unicode.org for given locale and saves the
9
10
  # Rails' I18n hash in the plugin +locale+ directory
@@ -33,7 +34,7 @@ namespace :import do
33
34
  # Setup variables
34
35
  locale = ENV['LOCALE']
35
36
  unless locale
36
- puts "\n[!] Usage: rake import:country_select LOCALE=de\n\n"
37
+ puts "\n[!] Usage: rails import:country_select LOCALE=de\n\n"
37
38
  exit 0
38
39
  end
39
40
 
@@ -46,7 +47,7 @@ namespace :import do
46
47
  # ----- Get the CLDR HTML --------------------------------------------------
47
48
  begin
48
49
  puts "... getting the HTML file for locale '#{web_locale}'"
49
- url = "http://www.unicode.org/cldr/data/charts/summary/#{web_locale}.html"
50
+ url = "https://unicode-org.github.io/cldr-staging/charts/37/summary/#{web_locale}.html"
50
51
  html = open(url).read
51
52
  rescue => e
52
53
  puts "[!] Invalid locale name '#{web_locale}'! Not found in CLDR (#{e})"
@@ -56,9 +57,14 @@ namespace :import do
56
57
 
57
58
  set_parser(ENV['PARSER']) if ENV['PARSER']
58
59
  puts "... parsing the HTML file using #{parser.name.split("::").last}"
59
- countries = parser.parse(html).inject([]) { |arr, (code, attrs)| arr << attrs }
60
+ countries = parser.parse(html).inject([]) { |arr, (_code, attrs)| arr << attrs }
60
61
  countries.sort_by! { |c| c[:code] }
62
+ puts '... fetching correct list of country codes and filtering translations'
63
+ correct_list = CSV.parse(open('https://raw.githubusercontent.com/datasets/un-locode/master/data/country-codes.csv').string)
64
+ country_codes = correct_list.map { |c| c[0] }
65
+ countries.delete_if { |c| !country_codes.member?(c[:code].to_s) }
61
66
  puts "\n\n... imported #{countries.count} countries:"
67
+
62
68
  puts countries.map { |c| "#{c[:code]}: #{c[:name]}" }.join(", ")
63
69
 
64
70
 
@@ -78,7 +84,7 @@ namespace :import do
78
84
  countries:
79
85
  HEAD
80
86
  countries.each do |country|
81
- output << " #{country[:code]}: \"#{country[:name]}\"\n"
87
+ output << " \"#{country[:code]}\": \"#{country[:name]}\"\n"
82
88
  end
83
89
 
84
90
  else # rb format
@@ -136,10 +142,10 @@ TAIL
136
142
  document.search("//tr").inject({}) do |hash, row|
137
143
  n = row.search("td[@class='n']")
138
144
  g = row.search("td")
139
- if n.inner_html =~ /NamesTerritories/ && g.count >= 7 && g[4].inner_html =~ /^[A-Z]{2}/
145
+ if n.inner_html =~ /Locale Display Names/ && g.count >= 6 && g[4].inner_html =~ /^[A-Z]{2}$/
140
146
  code = g[4].inner_text
141
147
  code = code[-code.size, 2].to_sym
142
- name = row.search("td[@class='v']").inner_text
148
+ name = row.search("td[@class='v']:not([@title])").inner_text
143
149
 
144
150
  hash[code] = {:code => code, :name => name.to_s}
145
151
  end
@@ -163,10 +169,10 @@ TAIL
163
169
  document.find("//tr").inject({}) do |hash, row|
164
170
  n = row.find("td[@class='n']")
165
171
  g = row.find("td")
166
- if n.map(&:content).join =~ /NamesTerritories/ && g.count >= 7 && g[4].inner_xml =~ /^[A-Z]{2}/
172
+ if n.map(&:content).join =~ /Locale Display Names/ && g.count >= 6 && g[4].inner_xml =~ /^[A-Z]{2}/
167
173
  code = g[4].content
168
174
  code = code[-code.size, 2].to_sym
169
- name = row.find("td[@class='v']").map(&:content).join
175
+ name = row.find("td[@class='v' and not(@title)]").map(&:content).join
170
176
 
171
177
  hash[code] ||= {:code => code, :name => name.to_s}
172
178
  end
@@ -95,7 +95,6 @@
95
95
  :GU => "Guam",
96
96
  :GW => "Guinea-Bissau",
97
97
  :GY => "Guyana",
98
- :HK => "Hongkong, zvláštní administrativní oblast Číny",
99
98
  :HK => "Hongkong",
100
99
  :HM => "Ostrovy Heard a McDonald",
101
100
  :HN => "Honduras",
@@ -149,7 +148,6 @@
149
148
  :ML => "Mali",
150
149
  :MM => "Myanmar",
151
150
  :MN => "Mongolsko",
152
- :MO => "Zvláštní administrativní oblast Číny Macao",
153
151
  :MO => "Macao",
154
152
  :MP => "Severní Mariany",
155
153
  :MQ => "Martinik",
@@ -253,7 +251,7 @@
253
251
  :ZM => "Zambie",
254
252
  :ZW => "Zimbabwe",
255
253
  :ZZ => "Neznámá nebo neplatná oblast",
256
- }
254
+ }
257
255
 
258
256
  }
259
257
  }
@@ -100,7 +100,6 @@
100
100
  :GU => "Guam",
101
101
  :GW => "Guinea-Bissau",
102
102
  :GY => "Guyana",
103
- :HK => "Hong Kong SAR China",
104
103
  :HK => "Hong Kong",
105
104
  :HM => "Heard Island and McDonald Islands",
106
105
  :HN => "Honduras",
@@ -156,7 +155,6 @@
156
155
  :ML => "Mali",
157
156
  :MM => "Myanmar",
158
157
  :MN => "Mongolia",
159
- :MO => "Macau SAR China",
160
158
  :MO => "Macau",
161
159
  :MP => "Northern Mariana Islands",
162
160
  :MQ => "Martinique",
@@ -269,7 +267,7 @@
269
267
  :ZM => "Zambia",
270
268
  :ZW => "Zimbabwe",
271
269
  :ZZ => "Unknown or Invalid Region",
272
- }
270
+ }
273
271
 
274
272
  }
275
273
  }
@@ -34,17 +34,15 @@ class LocalizedCountrySelectTest < Test::Unit::TestCase
34
34
  end
35
35
 
36
36
  def test_should_return_select_tag_with_proper_name_for_object
37
- # puts localized_country_select(:user, :country)
38
37
  assert localized_country_select(:user, :country) =~
39
- Regexp.new(Regexp.escape('<select id="user_country" name="user[country]">')),
38
+ Regexp.new(Regexp.escape('<select name="user[country]" id="user_country">')),
40
39
  "Should have proper name for object"
41
40
  end
42
41
 
43
42
  def test_should_return_select_tag_with_proper_name
44
- # puts localized_country_select_tag( "competition_submission[data][citizenship]", nil)
45
43
  assert localized_country_select_tag( "competition_submission[data][citizenship]", nil) =~
46
44
  Regexp.new(
47
- Regexp.escape('<select id="competition_submission_data_citizenship" name="competition_submission[data][citizenship]">') ),
45
+ Regexp.escape('<select name="competition_submission[data][citizenship]" id="competition_submission_data_citizenship">') ),
48
46
  "Should have proper name"
49
47
  end
50
48
 
@@ -70,7 +68,7 @@ class LocalizedCountrySelectTest < Test::Unit::TestCase
70
68
 
71
69
  def test_excludes_countries
72
70
  assert_nothing_raised { LocalizedCountrySelect::localized_countries_array(:exclude => :ZZ) }
73
-
71
+
74
72
  assert_block do
75
73
  not LocalizedCountrySelect::localized_countries_array(:exclude => :ZZ).any? {|country| country.last == "ZZ"}
76
74
  end
metadata CHANGED
@@ -1,8 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: localized_country_select
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.8
5
- prerelease:
4
+ version: 0.10.1
6
5
  platform: ruby
7
6
  authors:
8
7
  - karmi
@@ -10,54 +9,42 @@ authors:
10
9
  - LIM SAS
11
10
  - Damien MATHIEU
12
11
  - Julien SANCHEZ
13
- - Hervé GAUCHER
14
- - ! 'RainerBlessing '
15
- autorequire:
12
+ - Herv\303\251 GAUCHER
13
+ - RainerBlessing
14
+ autorequire:
16
15
  bindir: bin
17
16
  cert_chain: []
18
- date: 2014-03-28 00:00:00.000000000 Z
17
+ date: 2020-06-16 00:00:00.000000000 Z
19
18
  dependencies:
20
19
  - !ruby/object:Gem::Dependency
21
20
  name: actionpack
22
21
  requirement: !ruby/object:Gem::Requirement
23
- none: false
24
22
  requirements:
25
- - - ! '>='
23
+ - - ">="
26
24
  - !ruby/object:Gem::Version
27
- version: '3.0'
25
+ version: '5.0'
28
26
  type: :runtime
29
27
  prerelease: false
30
28
  version_requirements: !ruby/object:Gem::Requirement
31
- none: false
32
29
  requirements:
33
- - - ! '>='
30
+ - - ">="
34
31
  - !ruby/object:Gem::Version
35
- version: '3.0'
36
- - !ruby/object:Gem::Dependency
37
- name: rspec
38
- requirement: !ruby/object:Gem::Requirement
39
- none: false
40
- requirements:
41
- - - ! '>='
42
- - !ruby/object:Gem::Version
43
- version: 2.0.0
44
- type: :development
45
- prerelease: false
46
- version_requirements: !ruby/object:Gem::Requirement
47
- none: false
48
- requirements:
49
- - - ! '>='
50
- - !ruby/object:Gem::Version
51
- version: 2.0.0
52
- description: Localized "country_select" helper with Rake task for downloading locales
53
- from Unicode.org's CLDR
32
+ version: '5.0'
33
+ description: ' Localized "country_select" helper with Rake task for downloading locales
34
+ from Unicode.org''s CLDR '
54
35
  email:
36
+ -
55
37
  - maciej@litwiniuk.net
38
+ -
39
+ -
40
+ -
41
+ -
42
+ -
56
43
  executables: []
57
44
  extensions: []
58
45
  extra_rdoc_files: []
59
46
  files:
60
- - .gitignore
47
+ - ".gitignore"
61
48
  - MIT-LICENSE
62
49
  - README.rdoc
63
50
  - Rakefile
@@ -73,27 +60,25 @@ files:
73
60
  homepage: https://github.com/mlitwiniuk/localized_country_select
74
61
  licenses:
75
62
  - MIT
76
- post_install_message:
63
+ metadata: {}
64
+ post_install_message:
77
65
  rdoc_options: []
78
66
  require_paths:
79
67
  - lib
80
68
  required_ruby_version: !ruby/object:Gem::Requirement
81
- none: false
82
69
  requirements:
83
- - - ! '>='
70
+ - - ">="
84
71
  - !ruby/object:Gem::Version
85
72
  version: '0'
86
73
  required_rubygems_version: !ruby/object:Gem::Requirement
87
- none: false
88
74
  requirements:
89
- - - ! '>='
75
+ - - ">="
90
76
  - !ruby/object:Gem::Version
91
77
  version: '0'
92
78
  requirements: []
93
- rubyforge_project:
94
- rubygems_version: 1.8.23.2
95
- signing_key:
96
- specification_version: 3
79
+ rubygems_version: 3.0.3
80
+ signing_key:
81
+ specification_version: 4
97
82
  summary: Localized "country_select" helper with Rake task for downloading locales
98
83
  from Unicode.org's CLDR
99
84
  test_files: