country_select 2.0.1 → 2.1.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3e785c0581b426a8f17ea5360af83ee345feedcf
4
- data.tar.gz: f7694d0c2f41126fb93baa51c6b1d9abaf58ff52
3
+ metadata.gz: 0f72c7a94484b2fc7e537a8addc1ba2e3593edff
4
+ data.tar.gz: b88516afc9af4968d9e10f427504f9c92883185d
5
5
  SHA512:
6
- metadata.gz: eefc971e1428a53d7ceeca2669f9a9f29cc86d4b85c70bdbdb52b9e04ea53ca4de9f15bb5aa7f13260acc7d9e87d49a246fdc4896bb6f23efabf3a74edb38524
7
- data.tar.gz: 6483ee7c72a5609b75c02ec5336203feac1b6d26469e7f41e3a530a5c240f41e6e2ed3d4317457b1aa79b9805e20c2e5cb3c9093c8d7cb4efc35b457143df064
6
+ metadata.gz: 4ad51cc6825e7da7fcd12db138716df55812850768e1d293b2ad996b8b5f0500a38bed8b1a6c51b0cd6b0bee4c13fe18d1fc658ddfd04488ca247d0334dfde83
7
+ data.tar.gz: 4d9fa1e8e639330045a77e9b9dc126eecbf72eb0e2487e53715369383c962c5b80d403c9366e14be62f5f8439d8577b402be8be070b664e4eea5a667347c7b62
data/CHANGELOG.md CHANGED
@@ -1,10 +1,14 @@
1
- == 2.0.1 2014-09-18
1
+ ## 2.1.0 2014-09-29
2
+
3
+ * #70 - Allow custom formats for option tag text – See README.md
4
+
5
+ ## 2.0.1 2014-09-18
2
6
 
3
7
  * #72 - Fixed `include_blank` and `prompt` in Rails 3.2
4
8
  * #75 - Raise `CountrySelect::CountryNotFound` error when given a country
5
9
  name or code that is not found in https://github.com/hexorx/countries
6
10
 
7
- == 2.0.0 2014-08-10
11
+ ## 2.0.0 2014-08-10
8
12
 
9
13
  * Removed support for Ruby < 1.9.3
10
14
  * ISO-3166 alpha-2 codes are now on by default, stored in uppercase
@@ -20,7 +24,7 @@
20
24
  * Add best-guess support for country names when codes aren't provided
21
25
  in options (e.g., priority_countries)
22
26
 
23
- == 1.2.0 2013-07-06
27
+ ## 1.2.0 2013-07-06
24
28
 
25
29
  * Country names have been synced with UTF-8 encoding to the list of
26
30
  countries on [Wikipedia's page for the ISO-3166 standard](https://en.wikipedia.org/wiki/ISO_3166-1).
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- country_select (2.0.0)
4
+ country_select (2.0.1)
5
5
  countries (~> 0.9, >= 0.9.3)
6
6
 
7
7
  GEM
data/README.md CHANGED
@@ -57,6 +57,21 @@ Supplying additional html options:
57
57
  country_select("user", "country", { priority_countries: ["GB", "FR"] }, { selected: "GB", class: 'form-control' })
58
58
  ```
59
59
 
60
+ Using a custom formatter
61
+
62
+ You can define a custom formatter which will receive an
63
+ [`ISO3166::Country`](https://github.com/hexorx/countries/blob/master/lib/countries/country.rb)
64
+ ```ruby
65
+ # config/initializers/country_select.rb
66
+ CountrySelect::FORMATS[:with_alpha2] = lambda do |country|
67
+ "#{country.name} (#{country.alpha2})"
68
+ end
69
+ ```
70
+
71
+ ```ruby
72
+ country_select("user", "country", format: :with_alpha2)
73
+ ```
74
+
60
75
  ### ISO 3166-1 alpha-2 codes
61
76
  The `option` tags use ISO 3166-1 alpha-2 codes as values and the country
62
77
  names as display strings. For example, the United States would appear as
@@ -20,10 +20,10 @@ Gem::Specification.new do |s|
20
20
  s.require_paths = ['lib']
21
21
 
22
22
  s.add_development_dependency 'actionpack', '~> 3'
23
- s.add_development_dependency 'pry', '~> 0.10'
24
- s.add_development_dependency 'rake', '~> 10.3'
25
- s.add_development_dependency 'rspec', '~> 3.1'
26
- s.add_development_dependency 'wwtd', '~> 0.5'
23
+ s.add_development_dependency 'pry', '~> 0'
24
+ s.add_development_dependency 'rake'
25
+ s.add_development_dependency 'rspec', '~> 3'
26
+ s.add_development_dependency 'wwtd'
27
27
 
28
28
  s.add_dependency 'countries', '~> 0.9', '>= 0.9.3'
29
29
  end
@@ -25,7 +25,7 @@ GIT
25
25
  PATH
26
26
  remote: ../
27
27
  specs:
28
- country_select (2.0.0)
28
+ country_select (2.0.1)
29
29
  countries (~> 0.9, >= 0.9.3)
30
30
 
31
31
  GEM
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ../
3
3
  specs:
4
- country_select (2.0.0)
4
+ country_select (2.0.1)
5
5
  countries (~> 0.9, >= 0.9.3)
6
6
 
7
7
  GEM
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ../
3
3
  specs:
4
- country_select (2.0.0)
4
+ country_select (2.0.1)
5
5
  countries (~> 0.9, >= 0.9.3)
6
6
 
7
7
  GEM
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ../
3
3
  specs:
4
- country_select (2.0.0)
4
+ country_select (2.0.1)
5
5
  countries (~> 0.9, >= 0.9.3)
6
6
 
7
7
  GEM
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ../
3
3
  specs:
4
- country_select (2.0.0)
4
+ country_select (2.0.1)
5
5
  countries (~> 0.9, >= 0.9.3)
6
6
 
7
7
  GEM
@@ -3,6 +3,7 @@
3
3
  require 'iso3166'
4
4
 
5
5
  require 'country_select/version'
6
+ require 'country_select/formats'
6
7
  require 'country_select/tag_helper'
7
8
 
8
9
  if defined?(ActionView::Helpers::Tags::Base)
@@ -0,0 +1,7 @@
1
+ module CountrySelect
2
+ FORMATS = {}
3
+
4
+ FORMATS[:default] = lambda do |country|
5
+ country.translations[I18n.locale.to_s] || country.name
6
+ end
7
+ end
@@ -44,6 +44,10 @@ module CountrySelect
44
44
  @options[:except]
45
45
  end
46
46
 
47
+ def format
48
+ @options[:format] || :default
49
+ end
50
+
47
51
  def country_options
48
52
  country_options_for(all_country_codes, true)
49
53
  end
@@ -76,10 +80,7 @@ module CountrySelect
76
80
  raise CountryNotFoundError.new(msg)
77
81
  end
78
82
 
79
- default_name = country.name
80
- localized_name = country.translations[I18n.locale.to_s]
81
-
82
- name = localized_name || default_name
83
+ name = ::CountrySelect::FORMATS[format].call(country)
83
84
 
84
85
  [name,code]
85
86
  end
@@ -1,3 +1,3 @@
1
1
  module CountrySelect
2
- VERSION = "2.0.1"
2
+ VERSION = "2.1.0"
3
3
  end
@@ -164,4 +164,18 @@ describe "CountrySelect" do
164
164
  expect(t).to include(tag)
165
165
  end
166
166
  end
167
+
168
+ describe "custom formats" do
169
+ it "accepts a custom formatter" do
170
+ ::CountrySelect::FORMATS[:with_alpha2] = lambda do |country|
171
+ "#{country.name} (#{country.alpha2})"
172
+ end
173
+
174
+ tag = options_for_select([['United States (US)', 'US']], 'US')
175
+
176
+ walrus.country_code = 'US'
177
+ t = builder.country_select(:country_code, format: :with_alpha2)
178
+ expect(t).to include(tag)
179
+ end
180
+ end
167
181
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: country_select
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.1
4
+ version: 2.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stefan Penner
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-09-18 00:00:00.000000000 Z
11
+ date: 2014-09-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: actionpack
@@ -30,56 +30,56 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '0.10'
33
+ version: '0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '0.10'
40
+ version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rake
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - "~>"
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
- version: '10.3'
47
+ version: '0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - "~>"
52
+ - - ">="
53
53
  - !ruby/object:Gem::Version
54
- version: '10.3'
54
+ version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rspec
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '3.1'
61
+ version: '3'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: '3.1'
68
+ version: '3'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: wwtd
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - "~>"
73
+ - - ">="
74
74
  - !ruby/object:Gem::Version
75
- version: '0.5'
75
+ version: '0'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - "~>"
80
+ - - ">="
81
81
  - !ruby/object:Gem::Version
82
- version: '0.5'
82
+ version: '0'
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: countries
85
85
  requirement: !ruby/object:Gem::Requirement
@@ -122,8 +122,6 @@ files:
122
122
  - country_select.gemspec
123
123
  - gemfiles/actionpack.edge.gemfile
124
124
  - gemfiles/actionpack.edge.gemfile.lock
125
- - gemfiles/actionpack3.0.gemfile
126
- - gemfiles/actionpack3.1.gemfile
127
125
  - gemfiles/actionpack3.2.gemfile
128
126
  - gemfiles/actionpack3.2.gemfile.lock
129
127
  - gemfiles/actionpack4.0.gemfile
@@ -134,6 +132,7 @@ files:
134
132
  - gemfiles/actionpack4.2.gemfile.lock
135
133
  - lib/country_select.rb
136
134
  - lib/country_select/country_select_helper.rb
135
+ - lib/country_select/formats.rb
137
136
  - lib/country_select/rails3/country_select_helper.rb
138
137
  - lib/country_select/tag_helper.rb
139
138
  - lib/country_select/version.rb
@@ -1,11 +0,0 @@
1
- source "https://rubygems.org"
2
-
3
- gemspec :path => "../"
4
-
5
- gem "actionpack", "~> 3.0.20"
6
-
7
- platforms :rbx do
8
- gem "racc"
9
- gem "rubysl", "~> 2.0"
10
- gem "psych"
11
- end
@@ -1,11 +0,0 @@
1
- source "https://rubygems.org"
2
-
3
- gemspec :path => "../"
4
-
5
- gem "actionpack", "~> 3.1.12"
6
-
7
- platforms :rbx do
8
- gem "racc"
9
- gem "rubysl", "~> 2.0"
10
- gem "psych"
11
- end