localized_country_select 0.9.9 → 0.10.2

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: 2da19dd7e08e5645d6d9240208b9a05d9c6af19d7b1a110bbb1d41a21492ea2e
4
+ data.tar.gz: dcbe91207e4285c3c4628348628eacdf71e82d5e539b5d2ce16fb60b6fe94c9d
5
+ SHA512:
6
+ metadata.gz: 588343491e5967fd881a573ec33e913ee9c7f60c3b666861401ceec11b34b2fc6b95e3cb4b030532af852e13f2ae755c9ac2c9b11825fe465da8122027d58953
7
+ data.tar.gz: 6f25c06694dab02ca53dfdc932c58992403ccce1162536fa83cd572fdce70c9685ee06a61e3fd74fc518924ba184504547b36438ef7f04d1def545c859d96d16
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.2'
26
+
21
27
  == Rails 3 / Rails 4
22
28
 
23
29
  In your Gemfile add:
24
30
 
25
- gem 'localized_country_select', '>= 0.9.9'
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.9"
2
+ VERSION = '0.10.2'
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
 
@@ -136,7 +142,7 @@ 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 >= 6 && 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
148
  name = row.search("td[@class='v']:not([@title])").inner_text
@@ -163,7 +169,7 @@ 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 >= 6 && 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
175
  name = row.find("td[@class='v' and not(@title)]").map(&:content).join
@@ -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.9
5
- prerelease:
4
+ version: 0.10.2
6
5
  platform: ruby
7
6
  authors:
8
7
  - karmi
@@ -10,54 +9,44 @@ 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
+ - bbenno
15
+ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
- date: 2014-07-25 00:00:00.000000000 Z
18
+ date: 2020-07-20 00:00:00.000000000 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: actionpack
22
22
  requirement: !ruby/object:Gem::Requirement
23
- none: false
24
23
  requirements:
25
- - - ! '>='
24
+ - - ">="
26
25
  - !ruby/object:Gem::Version
27
- version: '3.0'
26
+ version: '5.0'
28
27
  type: :runtime
29
28
  prerelease: false
30
29
  version_requirements: !ruby/object:Gem::Requirement
31
- none: false
32
30
  requirements:
33
- - - ! '>='
31
+ - - ">="
34
32
  - !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
33
+ version: '5.0'
34
+ description: ' Localized "country_select" helper with Rake task for downloading locales
35
+ from Unicode.org''s CLDR '
54
36
  email:
37
+ -
55
38
  - maciej@litwiniuk.net
39
+ -
40
+ -
41
+ -
42
+ -
43
+ -
44
+ - bbenno@digitize-it.de
56
45
  executables: []
57
46
  extensions: []
58
47
  extra_rdoc_files: []
59
48
  files:
60
- - .gitignore
49
+ - ".gitignore"
61
50
  - MIT-LICENSE
62
51
  - README.rdoc
63
52
  - Rakefile
@@ -73,27 +62,25 @@ files:
73
62
  homepage: https://github.com/mlitwiniuk/localized_country_select
74
63
  licenses:
75
64
  - MIT
76
- post_install_message:
65
+ metadata: {}
66
+ post_install_message:
77
67
  rdoc_options: []
78
68
  require_paths:
79
69
  - lib
80
70
  required_ruby_version: !ruby/object:Gem::Requirement
81
- none: false
82
71
  requirements:
83
- - - ! '>='
72
+ - - ">="
84
73
  - !ruby/object:Gem::Version
85
74
  version: '0'
86
75
  required_rubygems_version: !ruby/object:Gem::Requirement
87
- none: false
88
76
  requirements:
89
- - - ! '>='
77
+ - - ">="
90
78
  - !ruby/object:Gem::Version
91
79
  version: '0'
92
80
  requirements: []
93
- rubyforge_project:
94
- rubygems_version: 1.8.23.2
95
- signing_key:
96
- specification_version: 3
81
+ rubygems_version: 3.0.3
82
+ signing_key:
83
+ specification_version: 4
97
84
  summary: Localized "country_select" helper with Rake task for downloading locales
98
85
  from Unicode.org's CLDR
99
86
  test_files: