brainsome_localized_country_select 0.9.10 → 0.9.11

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fa7f88f79da92af82183bb6c113c73087b6407d4
4
- data.tar.gz: 4e42189f21f557902411ef36feb6e2eec5400196
3
+ metadata.gz: ed07560553cc9d1e88798bf27c1106d8dd87a7d3
4
+ data.tar.gz: 35734cace6c5350f83600feca2a453a21a170ae1
5
5
  SHA512:
6
- metadata.gz: 70a864ff607803432057e72772f8645b9e988f44af3fccb4a4e25b83155689272bb68c9c3e8926c5f32e6b1ddf5af7373bbe78507bcab510045147e2e77534fa
7
- data.tar.gz: d44e34c3c28722686974e218f93b4157c7871467ec9e5b202a962f56df8a1efd18a09d50307945fd7182254ef2f645c377c91c024b8ffba3c7ce9e07e00fd2d7
6
+ metadata.gz: ca03b78aa6dcaa87ecbb11f0f3d941cda8421887da420634158d085f2040cafc905325a57c03bad266fb24d27585bea2a459433657eb901da79e89eed315151a
7
+ data.tar.gz: 740733393d6c432f63495aaf413c209e5c3d003cdc63debec211485c3790ff00cde418ad792cf8217f9297f114b1d880d843077ed716cc09547dc86d05ac52e3
@@ -22,7 +22,7 @@ See http://github.com/rails/country_select/tree/master/lib/country_select.rb
22
22
 
23
23
  In your Gemfile add:
24
24
 
25
- gem 'localized_country_select', '>= 0.9.9'
25
+ gem 'localized_country_select', '>= 0.9.11'
26
26
 
27
27
  == Rails 2.3
28
28
 
@@ -25,7 +25,7 @@ module LocalizedCountrySelect
25
25
  # for <tt><option></tt> tags
26
26
  def localized_countries_array(options={})
27
27
  exclude = Array(options[:exclude]).map {|code| code.to_s.upcase }
28
- locale = options.delete(:locale) || I18n.locale
28
+ locale = options[:locale] || I18n.locale
29
29
 
30
30
  if(options[:description]==:abbreviated)
31
31
  I18n.translate(:countries, locale: locale).map { |key, value| [key.to_s.upcase] if !exclude.include?(key.to_s.upcase) }
@@ -39,10 +39,12 @@ module LocalizedCountrySelect
39
39
  # priority_countries_array([:TW, :CN])
40
40
  # # => [ ['Taiwan', 'TW'], ['China', 'CN'] ]
41
41
  def priority_countries_array(country_codes=[],options={})
42
+ locale = options[:locale] || I18n.locale
43
+
42
44
  if(options[:description]==:abbreviated)
43
45
  country_codes.map { |code| [code.to_s.upcase] }
44
46
  else
45
- countries = I18n.translate(:countries)
47
+ countries = I18n.translate(:countries, locale: locale)
46
48
  country_codes.map { |code| [countries[code.to_s.upcase.to_sym], code.to_s.upcase] }
47
49
  end
48
50
  end
@@ -1,3 +1,3 @@
1
1
  module LocalizedCountrySelect
2
- VERSION = "0.9.10"
2
+ VERSION = "0.9.11"
3
3
  end
@@ -1,6 +1,7 @@
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
7
  # (http://www.unicode.org/cldr/data/charts/summary/root.html).
@@ -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
@@ -62,6 +62,16 @@ class LocalizedCountrySelectTest < Test::Unit::TestCase
62
62
  Regexp.escape("<option value=\"ES\">Spain</option>\n<option value=\"CZ\">Czech Republic</option><option value=\"\" disabled=\"disabled\">-------------</option>\n<option value=\"AF\">Afghanistan</option>\n"))
63
63
  end
64
64
 
65
+ def test_should_passing_locale_option
66
+ country_options_cz = localized_country_options_for_select(nil, nil, locale: :cz)
67
+ country_options_en = localized_country_options_for_select(nil, nil, locale: :en)
68
+ assert_not_equal country_options_cz, country_options_en
69
+
70
+ country_options_cz = localized_country_options_for_select(nil, [:ES, :CZ], locale: :cz)
71
+ country_options_en = localized_country_options_for_select(nil, [:ES, :CZ], locale: :en)
72
+ assert_not_equal country_options_cz, country_options_en
73
+ end
74
+
65
75
  def test_i18n_should_know_about_countries
66
76
  assert_equal 'Spain', I18n.t('ES', :scope => 'countries')
67
77
  I18n.locale = 'cz'
@@ -113,6 +123,12 @@ class LocalizedCountrySelectTest < Test::Unit::TestCase
113
123
  assert_equal [ ['United States', 'US'], ['Canada', 'CA'] ], LocalizedCountrySelect::priority_countries_array([:us, :ca])
114
124
  end
115
125
 
126
+ def test_priority_countries_allows_passing_locale_option
127
+ I18n.locale = 'cz'
128
+ assert_not_equal [ ['Taiwan', 'TW'], ['China', 'CN'] ], LocalizedCountrySelect::priority_countries_array([:TW, :CN])
129
+ assert_equal [ ['Taiwan', 'TW'], ['China', 'CN'] ], LocalizedCountrySelect::priority_countries_array([:TW, :CN], locale: :en)
130
+ end
131
+
116
132
  def test_should_list_countries_with_accented_names_in_correct_order
117
133
  I18n.locale = 'cz'
118
134
  assert_match Regexp.new(Regexp.escape(%Q{<option value="BI">Burundi</option>\n<option value="TD">Čad</option>})), localized_country_select(:user, :country)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: brainsome_localized_country_select
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.10
4
+ version: 0.9.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - karmi
@@ -15,22 +15,36 @@ authors:
15
15
  autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
- date: 2014-12-09 00:00:00.000000000 Z
18
+ date: 2015-07-02 00:00:00.000000000 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
- name: actionpack
21
+ name: bundler
22
22
  requirement: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ">="
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '3.0'
27
- type: :runtime
26
+ version: '1.6'
27
+ type: :development
28
28
  prerelease: false
29
29
  version_requirements: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ">="
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '3.0'
33
+ version: '1.6'
34
+ - !ruby/object:Gem::Dependency
35
+ name: rake
36
+ requirement: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ type: :development
42
+ prerelease: false
43
+ version_requirements: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
34
48
  - !ruby/object:Gem::Dependency
35
49
  name: rspec
36
50
  requirement: !ruby/object:Gem::Requirement
@@ -45,6 +59,20 @@ dependencies:
45
59
  - - ">="
46
60
  - !ruby/object:Gem::Version
47
61
  version: 2.0.0
62
+ - !ruby/object:Gem::Dependency
63
+ name: actionpack
64
+ requirement: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '3.0'
69
+ type: :runtime
70
+ prerelease: false
71
+ version_requirements: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '3.0'
48
76
  description: Localized "country_select" helper with Rake task for downloading locales
49
77
  from Unicode.org's CLDR
50
78
  email:
@@ -60,8 +88,6 @@ executables: []
60
88
  extensions: []
61
89
  extra_rdoc_files: []
62
90
  files:
63
- - ".gitignore"
64
- - ".travis.yml"
65
91
  - MIT-LICENSE
66
92
  - README.rdoc
67
93
  - Rakefile
data/.gitignore DELETED
@@ -1,21 +0,0 @@
1
- .DS_Store
2
- *.gem
3
- *.rbc
4
- .bundle
5
- .config
6
- .yardoc
7
- Gemfile.lock
8
- InstalledFiles
9
- _yardoc
10
- coverage
11
- doc/
12
- lib/bundler/man
13
- pkg
14
- rdoc
15
- spec/reports
16
- test/tmp
17
- test/version_tmp
18
- tmp
19
- .ruby-gemset
20
- .ruby-version
21
- .rvmrc
@@ -1,13 +0,0 @@
1
- language: ruby
2
- rvm:
3
- - 2.1.2
4
- - 2.1.1
5
- - 2.0.0
6
- - 1.9.3
7
- - 1.9.2
8
- - jruby-18mode
9
- - jruby-19mode
10
- - ruby-head
11
- - jruby-head
12
- - 1.8.7
13
- - ree