country_select 1.1.3 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/.rspec +2 -0
- data/.travis.yml +17 -0
- data/Appraisals +19 -0
- data/CHANGELOG.md +14 -0
- data/Gemfile +1 -3
- data/README.md +66 -13
- data/Rakefile +24 -1
- data/country_select.gemspec +16 -10
- data/gemfiles/actionpack3.0.gemfile +7 -0
- data/gemfiles/actionpack3.0.gemfile.lock +64 -0
- data/gemfiles/actionpack3.1.gemfile +7 -0
- data/gemfiles/actionpack3.1.gemfile.lock +72 -0
- data/gemfiles/actionpack3.2.gemfile +7 -0
- data/gemfiles/actionpack3.2.gemfile.lock +71 -0
- data/gemfiles/actionpack4.0.gemfile +7 -0
- data/gemfiles/actionpack4.0.gemfile.lock +62 -0
- data/lib/country_select.rb +77 -60
- data/lib/country_select/countries.rb +256 -0
- data/lib/country_select/version.rb +1 -1
- data/spec/country_select_spec.rb +133 -0
- data/spec/spec_helper.rb +20 -0
- metadata +87 -13
- data/VERSION +0 -1
data/.gitignore
CHANGED
data/.rspec
ADDED
data/.travis.yml
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
language: ruby
|
2
|
+
script: "bundle exec rake appraisal:integration"
|
3
|
+
rvm:
|
4
|
+
- ruby-head
|
5
|
+
- 2.0.0
|
6
|
+
- 1.9.3
|
7
|
+
- 1.9.2
|
8
|
+
- 1.8.7
|
9
|
+
- ree
|
10
|
+
- jruby-head
|
11
|
+
- jruby-19mode
|
12
|
+
- jruby-18mode
|
13
|
+
- rbx-19mode
|
14
|
+
- rbx-18mode
|
15
|
+
matrix:
|
16
|
+
allow_failures:
|
17
|
+
- rvm: ruby-head
|
data/Appraisals
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
# appraise 'actionpack2.3' do
|
2
|
+
# gem 'actionpack', '~> 2.3.0'
|
3
|
+
# end
|
4
|
+
|
5
|
+
appraise 'actionpack3.0' do
|
6
|
+
gem 'actionpack', '~> 3.0.0'
|
7
|
+
end
|
8
|
+
|
9
|
+
appraise 'actionpack3.1' do
|
10
|
+
gem 'actionpack', '~> 3.1.0'
|
11
|
+
end
|
12
|
+
|
13
|
+
appraise 'actionpack3.2' do
|
14
|
+
gem 'actionpack', '~> 3.2.0'
|
15
|
+
end
|
16
|
+
|
17
|
+
appraise 'actionpack4.0' do
|
18
|
+
gem 'actionpack', '~> 4.0.0'
|
19
|
+
end
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
== 1.2.0 2013-07-06
|
2
|
+
|
3
|
+
* Country names have been synced with UTF-8 encoding to the list of
|
4
|
+
countries on [Wikipedia's page for the ISO-3166 standard](https://en.wikipedia.org/wiki/ISO_3166-1).
|
5
|
+
* NOTE: This could be a breaking change with some of the country
|
6
|
+
names that have been fixed since the list was last updated.
|
7
|
+
* For more information you can checkout all country mappings with
|
8
|
+
`::CountrySelect::COUNTRIES`
|
9
|
+
|
10
|
+
* You can now store your country values using the
|
11
|
+
[ISO-3166 Alpha-2 codes](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2)
|
12
|
+
with the `iso_codes` option. See the README.md for details.
|
13
|
+
* This should help alleviate the problem of country names
|
14
|
+
in ISO-3166 being changed and/or corrected.
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,34 +1,87 @@
|
|
1
|
-
|
1
|
+
# Rails – Country Select
|
2
|
+
[![Build Status](https://travis-ci.org/stefanpenner/country_select.png?branch=master)](https://travis-ci.org/stefanpenner/country_select)
|
2
3
|
|
3
|
-
Provides a simple helper to get an HTML select list of countries
|
4
|
-
|
5
|
-
still offend some users.
|
4
|
+
Provides a simple helper to get an HTML select list of countries using the
|
5
|
+
[ISO 3166-1 standard](https://en.wikipedia.org/wiki/ISO_3166-1).
|
6
6
|
|
7
|
-
|
7
|
+
It is also configurable to use countries'
|
8
|
+
[ISO 3166-1 alpha-2 codes](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2)
|
9
|
+
as values and
|
10
|
+
[ISO 3166-1 names](https://en.wikipedia.org/wiki/ISO_3166-1)
|
11
|
+
as display strings.
|
12
|
+
|
13
|
+
While the ISO 3166 standard is a relatively neutral source of country
|
14
|
+
names, it may still offend some users. Developers are strongly advised
|
15
|
+
to evaluate the suitability of this list given their user base.
|
8
16
|
|
9
17
|
## Installation
|
10
18
|
|
11
19
|
Install as a gem using
|
12
20
|
|
13
|
-
|
14
|
-
|
21
|
+
```shell
|
22
|
+
gem install country_select
|
23
|
+
```
|
15
24
|
Or put the following in your Gemfile
|
16
25
|
|
17
|
-
|
26
|
+
```ruby
|
27
|
+
gem 'country_select'
|
28
|
+
```
|
18
29
|
|
19
30
|
## Example
|
20
31
|
|
21
32
|
Simple use supplying model and attribute as parameters:
|
22
33
|
|
23
|
-
|
34
|
+
```ruby
|
35
|
+
country_select("user", "country")
|
36
|
+
```
|
24
37
|
|
25
38
|
Supplying priority countries to be placed at the top of the list:
|
26
39
|
|
27
|
-
|
40
|
+
```ruby
|
41
|
+
country_select("user", "country", [ "Great Britain", "France", "Germany" ])
|
42
|
+
```
|
43
|
+
|
44
|
+
### Using ISO 3166-1 alpha-2 codes as values
|
45
|
+
You can have the `option` tags use ISO 3166-1 alpha-2 codes as values
|
46
|
+
and the country names as display strings. For example, the United States
|
47
|
+
would appear as `<option value="us">United States</option>`
|
48
|
+
|
49
|
+
If you're starting a new project, this is the recommended way to store
|
50
|
+
your country data since it will be more resistant to country names
|
51
|
+
changing.
|
52
|
+
|
53
|
+
```ruby
|
54
|
+
country_select("user", "country_code", nil, iso_codes: true)
|
55
|
+
```
|
56
|
+
|
57
|
+
```ruby
|
58
|
+
country_select("user", "country_code", [ "gb", "fr", "de" ], iso_codes: true)
|
59
|
+
```
|
60
|
+
|
61
|
+
#### Getting the Country from ISO codes
|
62
|
+
|
63
|
+
```ruby
|
64
|
+
class User < ActiveRecord::Base
|
65
|
+
|
66
|
+
# Assuming country_select is used with User attribute `country_code`
|
67
|
+
def country_name
|
68
|
+
::CountrySelect::COUNTRIES[country_code]
|
69
|
+
end
|
70
|
+
|
71
|
+
end
|
72
|
+
```
|
73
|
+
|
74
|
+
## Tests
|
75
|
+
|
76
|
+
```shell
|
77
|
+
bundle
|
78
|
+
bundle exec rspec
|
79
|
+
```
|
28
80
|
|
29
|
-
|
30
|
-
United Kingdom will be selected.
|
81
|
+
### Running with multiple versions of actionpack
|
31
82
|
|
32
|
-
|
83
|
+
```shell
|
84
|
+
bundle exec appraisal
|
85
|
+
```
|
33
86
|
|
34
87
|
Copyright (c) 2008 Michael Koziarski, released under the MIT license
|
data/Rakefile
CHANGED
@@ -1 +1,24 @@
|
|
1
|
-
require
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler/setup'
|
3
|
+
require 'bundler/gem_tasks'
|
4
|
+
|
5
|
+
require 'appraisal'
|
6
|
+
|
7
|
+
require 'rspec/core/rake_task'
|
8
|
+
RSpec::Core::RakeTask.new(:spec)
|
9
|
+
|
10
|
+
task :default => :spec
|
11
|
+
|
12
|
+
namespace :appraisal do
|
13
|
+
desc "Run the given task for a particular integration's appraisals"
|
14
|
+
task :integration do
|
15
|
+
Appraisal::File.each do |appraisal|
|
16
|
+
if RUBY_VERSION < '1.9.3' and appraisal.name == 'actionpack4.0'
|
17
|
+
# skip rails 4 for ruby < 1.9.3
|
18
|
+
else
|
19
|
+
appraisal.install
|
20
|
+
Appraisal::Command.from_args(appraisal.gemfile_path).run
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
data/country_select.gemspec
CHANGED
@@ -1,24 +1,30 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
|
-
$:.push File.expand_path(
|
3
|
-
require
|
2
|
+
$:.push File.expand_path('../lib', __FILE__)
|
3
|
+
require 'country_select/version'
|
4
4
|
|
5
5
|
Gem::Specification.new do |s|
|
6
|
-
s.name =
|
6
|
+
s.name = 'country_select'
|
7
7
|
s.version = CountrySelect::VERSION
|
8
|
-
s.authors = [
|
9
|
-
s.email = [
|
10
|
-
s.homepage =
|
8
|
+
s.authors = ['Stefan Penner']
|
9
|
+
s.email = ['stefan.penner@gmail.com']
|
10
|
+
s.homepage = 'https://github.com/stefanpenner/country_select'
|
11
11
|
s.summary = %q{Country Select Plugin}
|
12
12
|
s.description = %q{Provides a simple helper to get an HTML select list of countries. The list of countries comes from the ISO 3166 standard. While it is a relatively neutral source of country names, it will still offend some users.}
|
13
13
|
|
14
|
-
s.rubyforge_project =
|
14
|
+
s.rubyforge_project = 'country_select'
|
15
15
|
|
16
16
|
s.files = `git ls-files`.split("\n")
|
17
17
|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
18
18
|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
19
|
-
s.require_paths = [
|
19
|
+
s.require_paths = ['lib']
|
20
20
|
|
21
21
|
# specify any dependencies here; for example:
|
22
|
-
|
23
|
-
|
22
|
+
s.add_development_dependency 'rspec'
|
23
|
+
if RUBY_VERSION < '1.9.3'
|
24
|
+
s.add_development_dependency 'actionpack', '~> 3.2.13'
|
25
|
+
else
|
26
|
+
s.add_development_dependency 'actionpack'
|
27
|
+
end
|
28
|
+
s.add_development_dependency 'appraisal'
|
29
|
+
s.add_development_dependency 'pry'
|
24
30
|
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
PATH
|
2
|
+
remote: /Users/scudco/projects/country_select
|
3
|
+
specs:
|
4
|
+
country_select (1.1.3)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
abstract (1.0.0)
|
10
|
+
actionpack (3.0.20)
|
11
|
+
activemodel (= 3.0.20)
|
12
|
+
activesupport (= 3.0.20)
|
13
|
+
builder (~> 2.1.2)
|
14
|
+
erubis (~> 2.6.6)
|
15
|
+
i18n (~> 0.5.0)
|
16
|
+
rack (~> 1.2.5)
|
17
|
+
rack-mount (~> 0.6.14)
|
18
|
+
rack-test (~> 0.5.7)
|
19
|
+
tzinfo (~> 0.3.23)
|
20
|
+
activemodel (3.0.20)
|
21
|
+
activesupport (= 3.0.20)
|
22
|
+
builder (~> 2.1.2)
|
23
|
+
i18n (~> 0.5.0)
|
24
|
+
activesupport (3.0.20)
|
25
|
+
appraisal (0.5.2)
|
26
|
+
bundler
|
27
|
+
rake
|
28
|
+
builder (2.1.2)
|
29
|
+
coderay (1.0.9)
|
30
|
+
diff-lcs (1.2.4)
|
31
|
+
erubis (2.6.6)
|
32
|
+
abstract (>= 1.0.0)
|
33
|
+
i18n (0.5.0)
|
34
|
+
method_source (0.8.1)
|
35
|
+
pry (0.9.12.2)
|
36
|
+
coderay (~> 1.0.5)
|
37
|
+
method_source (~> 0.8)
|
38
|
+
slop (~> 3.4)
|
39
|
+
rack (1.2.8)
|
40
|
+
rack-mount (0.6.14)
|
41
|
+
rack (>= 1.0.0)
|
42
|
+
rack-test (0.5.7)
|
43
|
+
rack (>= 1.0)
|
44
|
+
rake (10.0.4)
|
45
|
+
rspec (2.13.0)
|
46
|
+
rspec-core (~> 2.13.0)
|
47
|
+
rspec-expectations (~> 2.13.0)
|
48
|
+
rspec-mocks (~> 2.13.0)
|
49
|
+
rspec-core (2.13.1)
|
50
|
+
rspec-expectations (2.13.0)
|
51
|
+
diff-lcs (>= 1.1.3, < 2.0)
|
52
|
+
rspec-mocks (2.13.1)
|
53
|
+
slop (3.4.5)
|
54
|
+
tzinfo (0.3.37)
|
55
|
+
|
56
|
+
PLATFORMS
|
57
|
+
ruby
|
58
|
+
|
59
|
+
DEPENDENCIES
|
60
|
+
actionpack (~> 3.0.0)
|
61
|
+
appraisal
|
62
|
+
country_select!
|
63
|
+
pry
|
64
|
+
rspec
|
@@ -0,0 +1,72 @@
|
|
1
|
+
PATH
|
2
|
+
remote: /Users/scudco/projects/country_select
|
3
|
+
specs:
|
4
|
+
country_select (1.1.3)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
actionpack (3.1.12)
|
10
|
+
activemodel (= 3.1.12)
|
11
|
+
activesupport (= 3.1.12)
|
12
|
+
builder (~> 3.0.0)
|
13
|
+
erubis (~> 2.7.0)
|
14
|
+
i18n (~> 0.6)
|
15
|
+
rack (~> 1.3.6)
|
16
|
+
rack-cache (~> 1.2)
|
17
|
+
rack-mount (~> 0.8.2)
|
18
|
+
rack-test (~> 0.6.1)
|
19
|
+
sprockets (~> 2.0.4)
|
20
|
+
activemodel (3.1.12)
|
21
|
+
activesupport (= 3.1.12)
|
22
|
+
builder (~> 3.0.0)
|
23
|
+
i18n (~> 0.6)
|
24
|
+
activesupport (3.1.12)
|
25
|
+
multi_json (~> 1.0)
|
26
|
+
appraisal (0.5.2)
|
27
|
+
bundler
|
28
|
+
rake
|
29
|
+
builder (3.0.4)
|
30
|
+
coderay (1.0.9)
|
31
|
+
diff-lcs (1.2.4)
|
32
|
+
erubis (2.7.0)
|
33
|
+
hike (1.2.2)
|
34
|
+
i18n (0.6.4)
|
35
|
+
method_source (0.8.1)
|
36
|
+
multi_json (1.7.3)
|
37
|
+
pry (0.9.12.2)
|
38
|
+
coderay (~> 1.0.5)
|
39
|
+
method_source (~> 0.8)
|
40
|
+
slop (~> 3.4)
|
41
|
+
rack (1.3.10)
|
42
|
+
rack-cache (1.2)
|
43
|
+
rack (>= 0.4)
|
44
|
+
rack-mount (0.8.3)
|
45
|
+
rack (>= 1.0.0)
|
46
|
+
rack-test (0.6.2)
|
47
|
+
rack (>= 1.0)
|
48
|
+
rake (10.0.4)
|
49
|
+
rspec (2.13.0)
|
50
|
+
rspec-core (~> 2.13.0)
|
51
|
+
rspec-expectations (~> 2.13.0)
|
52
|
+
rspec-mocks (~> 2.13.0)
|
53
|
+
rspec-core (2.13.1)
|
54
|
+
rspec-expectations (2.13.0)
|
55
|
+
diff-lcs (>= 1.1.3, < 2.0)
|
56
|
+
rspec-mocks (2.13.1)
|
57
|
+
slop (3.4.5)
|
58
|
+
sprockets (2.0.4)
|
59
|
+
hike (~> 1.2)
|
60
|
+
rack (~> 1.0)
|
61
|
+
tilt (~> 1.1, != 1.3.0)
|
62
|
+
tilt (1.4.1)
|
63
|
+
|
64
|
+
PLATFORMS
|
65
|
+
ruby
|
66
|
+
|
67
|
+
DEPENDENCIES
|
68
|
+
actionpack (~> 3.1.0)
|
69
|
+
appraisal
|
70
|
+
country_select!
|
71
|
+
pry
|
72
|
+
rspec
|
@@ -0,0 +1,71 @@
|
|
1
|
+
PATH
|
2
|
+
remote: /Users/scudco/projects/country_select
|
3
|
+
specs:
|
4
|
+
country_select (1.1.3)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
actionpack (3.2.13)
|
10
|
+
activemodel (= 3.2.13)
|
11
|
+
activesupport (= 3.2.13)
|
12
|
+
builder (~> 3.0.0)
|
13
|
+
erubis (~> 2.7.0)
|
14
|
+
journey (~> 1.0.4)
|
15
|
+
rack (~> 1.4.5)
|
16
|
+
rack-cache (~> 1.2)
|
17
|
+
rack-test (~> 0.6.1)
|
18
|
+
sprockets (~> 2.2.1)
|
19
|
+
activemodel (3.2.13)
|
20
|
+
activesupport (= 3.2.13)
|
21
|
+
builder (~> 3.0.0)
|
22
|
+
activesupport (3.2.13)
|
23
|
+
i18n (= 0.6.1)
|
24
|
+
multi_json (~> 1.0)
|
25
|
+
appraisal (0.5.2)
|
26
|
+
bundler
|
27
|
+
rake
|
28
|
+
builder (3.0.4)
|
29
|
+
coderay (1.0.9)
|
30
|
+
diff-lcs (1.2.4)
|
31
|
+
erubis (2.7.0)
|
32
|
+
hike (1.2.2)
|
33
|
+
i18n (0.6.1)
|
34
|
+
journey (1.0.4)
|
35
|
+
method_source (0.8.1)
|
36
|
+
multi_json (1.7.3)
|
37
|
+
pry (0.9.12.2)
|
38
|
+
coderay (~> 1.0.5)
|
39
|
+
method_source (~> 0.8)
|
40
|
+
slop (~> 3.4)
|
41
|
+
rack (1.4.5)
|
42
|
+
rack-cache (1.2)
|
43
|
+
rack (>= 0.4)
|
44
|
+
rack-test (0.6.2)
|
45
|
+
rack (>= 1.0)
|
46
|
+
rake (10.0.4)
|
47
|
+
rspec (2.13.0)
|
48
|
+
rspec-core (~> 2.13.0)
|
49
|
+
rspec-expectations (~> 2.13.0)
|
50
|
+
rspec-mocks (~> 2.13.0)
|
51
|
+
rspec-core (2.13.1)
|
52
|
+
rspec-expectations (2.13.0)
|
53
|
+
diff-lcs (>= 1.1.3, < 2.0)
|
54
|
+
rspec-mocks (2.13.1)
|
55
|
+
slop (3.4.5)
|
56
|
+
sprockets (2.2.2)
|
57
|
+
hike (~> 1.2)
|
58
|
+
multi_json (~> 1.0)
|
59
|
+
rack (~> 1.0)
|
60
|
+
tilt (~> 1.1, != 1.3.0)
|
61
|
+
tilt (1.4.1)
|
62
|
+
|
63
|
+
PLATFORMS
|
64
|
+
ruby
|
65
|
+
|
66
|
+
DEPENDENCIES
|
67
|
+
actionpack (~> 3.2.0)
|
68
|
+
appraisal
|
69
|
+
country_select!
|
70
|
+
pry
|
71
|
+
rspec
|
@@ -0,0 +1,62 @@
|
|
1
|
+
PATH
|
2
|
+
remote: /Users/scudco/projects/country_select
|
3
|
+
specs:
|
4
|
+
country_select (1.1.3)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
actionpack (4.0.0)
|
10
|
+
activesupport (= 4.0.0)
|
11
|
+
builder (~> 3.1.0)
|
12
|
+
erubis (~> 2.7.0)
|
13
|
+
rack (~> 1.5.2)
|
14
|
+
rack-test (~> 0.6.2)
|
15
|
+
activesupport (4.0.0)
|
16
|
+
i18n (~> 0.6, >= 0.6.4)
|
17
|
+
minitest (~> 4.2)
|
18
|
+
multi_json (~> 1.3)
|
19
|
+
thread_safe (~> 0.1)
|
20
|
+
tzinfo (~> 0.3.37)
|
21
|
+
appraisal (0.5.2)
|
22
|
+
bundler
|
23
|
+
rake
|
24
|
+
atomic (1.1.10)
|
25
|
+
builder (3.1.4)
|
26
|
+
coderay (1.0.9)
|
27
|
+
diff-lcs (1.2.4)
|
28
|
+
erubis (2.7.0)
|
29
|
+
i18n (0.6.4)
|
30
|
+
method_source (0.8.1)
|
31
|
+
minitest (4.7.5)
|
32
|
+
multi_json (1.7.7)
|
33
|
+
pry (0.9.12.2)
|
34
|
+
coderay (~> 1.0.5)
|
35
|
+
method_source (~> 0.8)
|
36
|
+
slop (~> 3.4)
|
37
|
+
rack (1.5.2)
|
38
|
+
rack-test (0.6.2)
|
39
|
+
rack (>= 1.0)
|
40
|
+
rake (10.1.0)
|
41
|
+
rspec (2.13.0)
|
42
|
+
rspec-core (~> 2.13.0)
|
43
|
+
rspec-expectations (~> 2.13.0)
|
44
|
+
rspec-mocks (~> 2.13.0)
|
45
|
+
rspec-core (2.13.1)
|
46
|
+
rspec-expectations (2.13.0)
|
47
|
+
diff-lcs (>= 1.1.3, < 2.0)
|
48
|
+
rspec-mocks (2.13.1)
|
49
|
+
slop (3.4.5)
|
50
|
+
thread_safe (0.1.0)
|
51
|
+
atomic
|
52
|
+
tzinfo (0.3.37)
|
53
|
+
|
54
|
+
PLATFORMS
|
55
|
+
ruby
|
56
|
+
|
57
|
+
DEPENDENCIES
|
58
|
+
actionpack (~> 4.0.0)
|
59
|
+
appraisal
|
60
|
+
country_select!
|
61
|
+
pry
|
62
|
+
rspec
|
data/lib/country_select.rb
CHANGED
@@ -1,92 +1,104 @@
|
|
1
1
|
# CountrySelect
|
2
|
+
#
|
3
|
+
# Adds #country_select method to
|
4
|
+
# ActionView::FormBuilder
|
5
|
+
#
|
2
6
|
require 'country_select/version'
|
7
|
+
require 'country_select/countries'
|
3
8
|
|
4
9
|
module ActionView
|
5
10
|
module Helpers
|
6
11
|
module FormOptionsHelper
|
7
|
-
#
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
12
|
+
#
|
13
|
+
# Return select and option tags
|
14
|
+
# for the given object and method,
|
15
|
+
# using country_options_for_select to
|
16
|
+
# generate the list of option tags.
|
17
|
+
#
|
18
|
+
def country_select(object, method, priority_countries = nil,
|
19
|
+
options = {},
|
20
|
+
html_options = {})
|
21
|
+
|
22
|
+
tag = if defined?(ActionView::Helpers::InstanceTag) &&
|
23
|
+
ActionView::Helpers::InstanceTag.instance_method(:initialize).arity != 0
|
24
|
+
|
25
|
+
InstanceTag.new(object, method, self, options.delete(:object))
|
26
|
+
else
|
27
|
+
CountrySelect.new(object, method, self, options)
|
28
|
+
end
|
29
|
+
|
30
|
+
tag.to_country_select_tag(priority_countries, options, html_options)
|
15
31
|
end
|
16
|
-
|
17
|
-
# have it marked as the selected option tag. You can also supply an array of countries as +priority_countries+, so
|
18
|
-
# that they will be listed above the rest of the (long) list.
|
32
|
+
|
19
33
|
#
|
20
|
-
#
|
21
|
-
|
34
|
+
# Returns a string of option tags for
|
35
|
+
# pretty much any country in the world.
|
36
|
+
#
|
37
|
+
# You can also supply an array of countries as
|
38
|
+
# +priority_countries+ so that they will be
|
39
|
+
# listed above the rest of the (long) list.
|
40
|
+
#
|
41
|
+
# NOTE: Only the option tags are returned, you
|
42
|
+
# have to wrap this call in a regular HTML
|
43
|
+
# select tag.
|
44
|
+
#
|
45
|
+
def country_options_for_select(selected = nil, priority_countries = nil, use_iso_codes = false)
|
22
46
|
country_options = "".html_safe
|
23
47
|
|
24
48
|
if priority_countries
|
25
|
-
|
49
|
+
priority_countries_options = if use_iso_codes
|
50
|
+
priority_countries.map do |code|
|
51
|
+
[
|
52
|
+
::CountrySelect::COUNTRIES[code],
|
53
|
+
code
|
54
|
+
]
|
55
|
+
end
|
56
|
+
else
|
57
|
+
priority_countries
|
58
|
+
end
|
59
|
+
|
60
|
+
country_options += options_for_select(priority_countries_options, selected)
|
26
61
|
country_options += "<option value=\"\" disabled=\"disabled\">-------------</option>\n".html_safe
|
27
|
-
#
|
28
|
-
#
|
29
|
-
#
|
30
|
-
|
62
|
+
#
|
63
|
+
# prevents selected from being included
|
64
|
+
# twice in the HTML which causes
|
65
|
+
# some browsers to select the second
|
66
|
+
# selected option (not priority)
|
67
|
+
# which makes it harder to select an
|
68
|
+
# alternative priority country
|
69
|
+
#
|
70
|
+
selected = nil if priority_countries.include?(selected)
|
31
71
|
end
|
32
72
|
|
33
|
-
|
73
|
+
values = if use_iso_codes
|
74
|
+
::CountrySelect::ISO_COUNTRIES_FOR_SELECT
|
75
|
+
else
|
76
|
+
::CountrySelect::COUNTRIES_FOR_SELECT
|
77
|
+
end
|
78
|
+
|
79
|
+
return country_options + options_for_select(values, selected)
|
34
80
|
end
|
81
|
+
|
35
82
|
# All the countries included in the country_options output.
|
36
|
-
COUNTRIES = ["Afghanistan", "Aland Islands", "Albania", "Algeria", "American Samoa", "Andorra", "Angola",
|
37
|
-
"Anguilla", "Antarctica", "Antigua And Barbuda", "Argentina", "Armenia", "Aruba", "Australia", "Austria",
|
38
|
-
"Azerbaijan", "Bahamas", "Bahrain", "Bangladesh", "Barbados", "Belarus", "Belgium", "Belize", "Benin",
|
39
|
-
"Bermuda", "Bhutan", "Bolivia", "Bosnia and Herzegovina", "Botswana", "Bouvet Island", "Brazil",
|
40
|
-
"British Indian Ocean Territory", "Brunei Darussalam", "Bulgaria", "Burkina Faso", "Burundi", "Cambodia",
|
41
|
-
"Cameroon", "Canada", "Cape Verde", "Cayman Islands", "Central African Republic", "Chad", "Chile", "China",
|
42
|
-
"Christmas Island", "Cocos (Keeling) Islands", "Colombia", "Comoros", "Congo",
|
43
|
-
"Congo, the Democratic Republic of the", "Cook Islands", "Costa Rica", "Cote d'Ivoire", "Croatia", "Cuba",
|
44
|
-
"Curacao", "Cyprus", "Czech Republic", "Denmark", "Djibouti", "Dominica", "Dominican Republic", "Ecuador", "Egypt",
|
45
|
-
"El Salvador", "Equatorial Guinea", "Eritrea", "Estonia", "Ethiopia", "Falkland Islands (Malvinas)",
|
46
|
-
"Faroe Islands", "Fiji", "Finland", "France", "French Guiana", "French Polynesia",
|
47
|
-
"French Southern Territories", "Gabon", "Gambia", "Georgia", "Germany", "Ghana", "Gibraltar", "Greece", "Greenland", "Grenada", "Guadeloupe", "Guam", "Guatemala", "Guernsey", "Guinea",
|
48
|
-
"Guinea-Bissau", "Guyana", "Haiti", "Heard and McDonald Islands", "Holy See (Vatican City State)",
|
49
|
-
"Honduras", "Hong Kong", "Hungary", "Iceland", "India", "Indonesia", "Iran, Islamic Republic of", "Iraq",
|
50
|
-
"Ireland", "Isle of Man", "Israel", "Italy", "Jamaica", "Japan", "Jersey", "Jordan", "Kazakhstan", "Kenya",
|
51
|
-
"Kiribati", "Korea, Democratic People's Republic of", "Korea, Republic of", "Kuwait", "Kyrgyzstan",
|
52
|
-
"Lao People's Democratic Republic", "Latvia", "Lebanon", "Lesotho", "Liberia", "Libyan Arab Jamahiriya",
|
53
|
-
"Liechtenstein", "Lithuania", "Luxembourg", "Macao", "Macedonia, The Former Yugoslav Republic Of",
|
54
|
-
"Madagascar", "Malawi", "Malaysia", "Maldives", "Mali", "Malta", "Marshall Islands", "Martinique",
|
55
|
-
"Mauritania", "Mauritius", "Mayotte", "Mexico", "Micronesia, Federated States of", "Moldova, Republic of",
|
56
|
-
"Monaco", "Mongolia", "Montenegro", "Montserrat", "Morocco", "Mozambique", "Myanmar", "Namibia", "Nauru",
|
57
|
-
"Nepal", "Netherlands", "New Caledonia", "New Zealand", "Nicaragua", "Niger",
|
58
|
-
"Nigeria", "Niue", "Norfolk Island", "Northern Mariana Islands", "Norway", "Oman", "Pakistan", "Palau",
|
59
|
-
"Palestinian Territory, Occupied", "Panama", "Papua New Guinea", "Paraguay", "Peru", "Philippines",
|
60
|
-
"Pitcairn", "Poland", "Portugal", "Puerto Rico", "Qatar", "Reunion", "Romania", "Russian Federation",
|
61
|
-
"Rwanda", "Saint Barthelemy", "Saint Helena", "Saint Kitts and Nevis", "Saint Lucia",
|
62
|
-
"Saint Pierre and Miquelon", "Saint Vincent and the Grenadines", "Samoa", "San Marino",
|
63
|
-
"Sao Tome and Principe", "Saudi Arabia", "Senegal", "Serbia", "Seychelles", "Sierra Leone", "Singapore",
|
64
|
-
"Sint Maarten","Slovakia", "Slovenia", "Solomon Islands", "Somalia", "South Africa",
|
65
|
-
"South Georgia and the South Sandwich Islands", "Spain", "Sri Lanka", "Sudan", "Suriname",
|
66
|
-
"Svalbard and Jan Mayen", "Swaziland", "Sweden", "Switzerland", "Syrian Arab Republic",
|
67
|
-
"Taiwan", "Tajikistan", "Tanzania, United Republic of", "Thailand", "Timor-Leste",
|
68
|
-
"Togo", "Tokelau", "Tonga", "Trinidad and Tobago", "Tunisia", "Turkey", "Turkmenistan",
|
69
|
-
"Turks and Caicos Islands", "Tuvalu", "Uganda", "Ukraine", "United Arab Emirates", "United Kingdom",
|
70
|
-
"United States", "United States Minor Outlying Islands", "Uruguay", "Uzbekistan", "Vanuatu", "Venezuela",
|
71
|
-
"Viet Nam", "Virgin Islands, British", "Virgin Islands, U.S.", "Wallis and Futuna", "Western Sahara",
|
72
|
-
"Yemen", "Zambia", "Zimbabwe"] unless const_defined?("COUNTRIES")
|
73
83
|
end
|
74
84
|
|
75
85
|
module ToCountrySelectTag
|
76
86
|
def to_country_select_tag(priority_countries, options, html_options)
|
87
|
+
use_iso_codes = options.delete(:iso_codes)
|
77
88
|
html_options = html_options.stringify_keys
|
78
89
|
add_default_name_and_id(html_options)
|
79
90
|
value = value(object)
|
80
91
|
content_tag("select",
|
81
92
|
add_options(
|
82
|
-
country_options_for_select(value, priority_countries),
|
93
|
+
country_options_for_select(value, priority_countries, use_iso_codes),
|
83
94
|
options, value
|
84
95
|
), html_options
|
85
96
|
)
|
86
97
|
end
|
87
98
|
end
|
88
99
|
|
89
|
-
if defined?(ActionView::Helpers::InstanceTag) &&
|
100
|
+
if defined?(ActionView::Helpers::InstanceTag) &&
|
101
|
+
ActionView::Helpers::InstanceTag.instance_method(:initialize).arity != 0
|
90
102
|
class InstanceTag
|
91
103
|
include ToCountrySelectTag
|
92
104
|
end
|
@@ -97,8 +109,13 @@ module ActionView
|
|
97
109
|
end
|
98
110
|
|
99
111
|
class FormBuilder
|
100
|
-
def country_select(method, priority_countries = nil,
|
101
|
-
|
112
|
+
def country_select(method, priority_countries = nil,
|
113
|
+
options = {},
|
114
|
+
html_options = {})
|
115
|
+
|
116
|
+
@template.country_select(@object_name, method, priority_countries,
|
117
|
+
options.merge(:object => @object),
|
118
|
+
html_options)
|
102
119
|
end
|
103
120
|
end
|
104
121
|
end
|
@@ -0,0 +1,256 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
module CountrySelect
|
3
|
+
COUNTRIES = {
|
4
|
+
"af" => "Afghanistan",
|
5
|
+
"ax" => "Åland Islands",
|
6
|
+
"al" => "Albania",
|
7
|
+
"dz" => "Algeria",
|
8
|
+
"as" => "American Samoa",
|
9
|
+
"ad" => "Andorra",
|
10
|
+
"ao" => "Angola",
|
11
|
+
"ai" => "Anguilla",
|
12
|
+
"aq" => "Antarctica",
|
13
|
+
"ag" => "Antigua and Barbuda",
|
14
|
+
"ar" => "Argentina",
|
15
|
+
"am" => "Armenia",
|
16
|
+
"aw" => "Aruba",
|
17
|
+
"au" => "Australia",
|
18
|
+
"at" => "Austria",
|
19
|
+
"az" => "Azerbaijan",
|
20
|
+
"bs" => "Bahamas",
|
21
|
+
"bh" => "Bahrain",
|
22
|
+
"bd" => "Bangladesh",
|
23
|
+
"bb" => "Barbados",
|
24
|
+
"by" => "Belarus",
|
25
|
+
"be" => "Belgium",
|
26
|
+
"bz" => "Belize",
|
27
|
+
"bj" => "Benin",
|
28
|
+
"bm" => "Bermuda",
|
29
|
+
"bt" => "Bhutan",
|
30
|
+
"bo" => "Bolivia, Plurinational State of",
|
31
|
+
"bq" => "Bonaire, Sint Eustatius and Saba",
|
32
|
+
"ba" => "Bosnia and Herzegovina",
|
33
|
+
"bw" => "Botswana",
|
34
|
+
"bv" => "Bouvet Island",
|
35
|
+
"br" => "Brazil",
|
36
|
+
"io" => "British Indian Ocean Territory",
|
37
|
+
"bn" => "Brunei Darussalam",
|
38
|
+
"bg" => "Bulgaria",
|
39
|
+
"bf" => "Burkina Faso",
|
40
|
+
"bi" => "Burundi",
|
41
|
+
"kh" => "Cambodia",
|
42
|
+
"cm" => "Cameroon",
|
43
|
+
"ca" => "Canada",
|
44
|
+
"cv" => "Cape Verde",
|
45
|
+
"ky" => "Cayman Islands",
|
46
|
+
"cf" => "Central African Republic",
|
47
|
+
"td" => "Chad",
|
48
|
+
"cl" => "Chile",
|
49
|
+
"cn" => "China",
|
50
|
+
"cx" => "Christmas Island",
|
51
|
+
"cc" => "Cocos (Keeling) Islands",
|
52
|
+
"co" => "Colombia",
|
53
|
+
"km" => "Comoros",
|
54
|
+
"cg" => "Congo",
|
55
|
+
"cd" => "Congo, the Democratic Republic of the",
|
56
|
+
"ck" => "Cook Islands",
|
57
|
+
"cr" => "Costa Rica",
|
58
|
+
"ci" => "Côte d'Ivoire",
|
59
|
+
"hr" => "Croatia",
|
60
|
+
"cu" => "Cuba",
|
61
|
+
"cw" => "Curaçao",
|
62
|
+
"cy" => "Cyprus",
|
63
|
+
"cz" => "Czech Republic",
|
64
|
+
"dk" => "Denmark",
|
65
|
+
"dj" => "Djibouti",
|
66
|
+
"dm" => "Dominica",
|
67
|
+
"do" => "Dominican Republic",
|
68
|
+
"ec" => "Ecuador",
|
69
|
+
"eg" => "Egypt",
|
70
|
+
"sv" => "El Salvador",
|
71
|
+
"gq" => "Equatorial Guinea",
|
72
|
+
"er" => "Eritrea",
|
73
|
+
"ee" => "Estonia",
|
74
|
+
"et" => "Ethiopia",
|
75
|
+
"fk" => "Falkland Islands (Malvinas)",
|
76
|
+
"fo" => "Faroe Islands",
|
77
|
+
"fj" => "Fiji",
|
78
|
+
"fi" => "Finland",
|
79
|
+
"fr" => "France",
|
80
|
+
"gf" => "French Guiana",
|
81
|
+
"pf" => "French Polynesia",
|
82
|
+
"tf" => "French Southern Territories",
|
83
|
+
"ga" => "Gabon",
|
84
|
+
"gm" => "Gambia",
|
85
|
+
"ge" => "Georgia",
|
86
|
+
"de" => "Germany",
|
87
|
+
"gh" => "Ghana",
|
88
|
+
"gi" => "Gibraltar",
|
89
|
+
"gr" => "Greece",
|
90
|
+
"gl" => "Greenland",
|
91
|
+
"gd" => "Grenada",
|
92
|
+
"gp" => "Guadeloupe",
|
93
|
+
"gu" => "Guam",
|
94
|
+
"gt" => "Guatemala",
|
95
|
+
"gg" => "Guernsey",
|
96
|
+
"gn" => "Guinea",
|
97
|
+
"gw" => "Guinea-Bissau",
|
98
|
+
"gy" => "Guyana",
|
99
|
+
"ht" => "Haiti",
|
100
|
+
"hm" => "Heard Island and McDonald Islands",
|
101
|
+
"va" => "Holy See (Vatican City State)",
|
102
|
+
"hn" => "Honduras",
|
103
|
+
"hk" => "Hong Kong",
|
104
|
+
"hu" => "Hungary",
|
105
|
+
"is" => "Iceland",
|
106
|
+
"in" => "India",
|
107
|
+
"id" => "Indonesia",
|
108
|
+
"ir" => "Iran, Islamic Republic of",
|
109
|
+
"iq" => "Iraq",
|
110
|
+
"ie" => "Ireland",
|
111
|
+
"im" => "Isle of Man",
|
112
|
+
"il" => "Israel",
|
113
|
+
"it" => "Italy",
|
114
|
+
"jm" => "Jamaica",
|
115
|
+
"jp" => "Japan",
|
116
|
+
"je" => "Jersey",
|
117
|
+
"jo" => "Jordan",
|
118
|
+
"kz" => "Kazakhstan",
|
119
|
+
"ke" => "Kenya",
|
120
|
+
"ki" => "Kiribati",
|
121
|
+
"kp" => "Korea, Democratic People's Republic of",
|
122
|
+
"kr" => "Korea, Republic of",
|
123
|
+
"kw" => "Kuwait",
|
124
|
+
"kg" => "Kyrgyzstan",
|
125
|
+
"la" => "Lao People's Democratic Republic",
|
126
|
+
"lv" => "Latvia",
|
127
|
+
"lb" => "Lebanon",
|
128
|
+
"ls" => "Lesotho",
|
129
|
+
"lr" => "Liberia",
|
130
|
+
"ly" => "Libya",
|
131
|
+
"li" => "Liechtenstein",
|
132
|
+
"lt" => "Lithuania",
|
133
|
+
"lu" => "Luxembourg",
|
134
|
+
"mo" => "Macao",
|
135
|
+
"mk" => "Macedonia, the former Yugoslav Republic of",
|
136
|
+
"mg" => "Madagascar",
|
137
|
+
"mw" => "Malawi",
|
138
|
+
"my" => "Malaysia",
|
139
|
+
"mv" => "Maldives",
|
140
|
+
"ml" => "Mali",
|
141
|
+
"mt" => "Malta",
|
142
|
+
"mh" => "Marshall Islands",
|
143
|
+
"mq" => "Martinique",
|
144
|
+
"mr" => "Mauritania",
|
145
|
+
"mu" => "Mauritius",
|
146
|
+
"yt" => "Mayotte",
|
147
|
+
"mx" => "Mexico",
|
148
|
+
"fm" => "Micronesia, Federated States of",
|
149
|
+
"md" => "Moldova, Republic of",
|
150
|
+
"mc" => "Monaco",
|
151
|
+
"mn" => "Mongolia",
|
152
|
+
"me" => "Montenegro",
|
153
|
+
"ms" => "Montserrat",
|
154
|
+
"ma" => "Morocco",
|
155
|
+
"mz" => "Mozambique",
|
156
|
+
"mm" => "Myanmar",
|
157
|
+
"na" => "Namibia",
|
158
|
+
"nr" => "Nauru",
|
159
|
+
"np" => "Nepal",
|
160
|
+
"nl" => "Netherlands",
|
161
|
+
"nc" => "New Caledonia",
|
162
|
+
"nz" => "New Zealand",
|
163
|
+
"ni" => "Nicaragua",
|
164
|
+
"ne" => "Niger",
|
165
|
+
"ng" => "Nigeria",
|
166
|
+
"nu" => "Niue",
|
167
|
+
"nf" => "Norfolk Island",
|
168
|
+
"mp" => "Northern Mariana Islands",
|
169
|
+
"no" => "Norway",
|
170
|
+
"om" => "Oman",
|
171
|
+
"pk" => "Pakistan",
|
172
|
+
"pw" => "Palau",
|
173
|
+
"ps" => "Palestine, State of",
|
174
|
+
"pa" => "Panama",
|
175
|
+
"pg" => "Papua New Guinea",
|
176
|
+
"py" => "Paraguay",
|
177
|
+
"pe" => "Peru",
|
178
|
+
"ph" => "Philippines",
|
179
|
+
"pn" => "Pitcairn",
|
180
|
+
"pl" => "Poland",
|
181
|
+
"pt" => "Portugal",
|
182
|
+
"pr" => "Puerto Rico",
|
183
|
+
"qa" => "Qatar",
|
184
|
+
"re" => "Réunion",
|
185
|
+
"ro" => "Romania",
|
186
|
+
"ru" => "Russian Federation",
|
187
|
+
"rw" => "Rwanda",
|
188
|
+
"bl" => "Saint Barthélemy",
|
189
|
+
"sh" => "Saint Helena, Ascension and Tristan da Cunha",
|
190
|
+
"kn" => "Saint Kitts and Nevis",
|
191
|
+
"lc" => "Saint Lucia",
|
192
|
+
"mf" => "Saint Martin (French part)",
|
193
|
+
"pm" => "Saint Pierre and Miquelon",
|
194
|
+
"vc" => "Saint Vincent and the Grenadines",
|
195
|
+
"ws" => "Samoa",
|
196
|
+
"sm" => "San Marino",
|
197
|
+
"st" => "Sao Tome and Principe",
|
198
|
+
"sa" => "Saudi Arabia",
|
199
|
+
"sn" => "Senegal",
|
200
|
+
"rs" => "Serbia",
|
201
|
+
"sc" => "Seychelles",
|
202
|
+
"sl" => "Sierra Leone",
|
203
|
+
"sg" => "Singapore",
|
204
|
+
"sx" => "Sint Maarten (Dutch part)",
|
205
|
+
"sk" => "Slovakia",
|
206
|
+
"si" => "Slovenia",
|
207
|
+
"sb" => "Solomon Islands",
|
208
|
+
"so" => "Somalia",
|
209
|
+
"za" => "South Africa",
|
210
|
+
"gs" => "South Georgia and the South Sandwich Islands",
|
211
|
+
"ss" => "South Sudan",
|
212
|
+
"es" => "Spain",
|
213
|
+
"lk" => "Sri Lanka",
|
214
|
+
"sd" => "Sudan",
|
215
|
+
"sr" => "Suriname",
|
216
|
+
"sj" => "Svalbard and Jan Mayen",
|
217
|
+
"sz" => "Swaziland",
|
218
|
+
"se" => "Sweden",
|
219
|
+
"ch" => "Switzerland",
|
220
|
+
"sy" => "Syrian Arab Republic",
|
221
|
+
"tw" => "Taiwan, Province of China",
|
222
|
+
"tj" => "Tajikistan",
|
223
|
+
"tz" => "Tanzania, United Republic of",
|
224
|
+
"th" => "Thailand",
|
225
|
+
"tl" => "Timor-Leste",
|
226
|
+
"tg" => "Togo",
|
227
|
+
"tk" => "Tokelau",
|
228
|
+
"to" => "Tonga",
|
229
|
+
"tt" => "Trinidad and Tobago",
|
230
|
+
"tn" => "Tunisia",
|
231
|
+
"tr" => "Turkey",
|
232
|
+
"tm" => "Turkmenistan",
|
233
|
+
"tc" => "Turks and Caicos Islands",
|
234
|
+
"tv" => "Tuvalu",
|
235
|
+
"ug" => "Uganda",
|
236
|
+
"ua" => "Ukraine",
|
237
|
+
"ae" => "United Arab Emirates",
|
238
|
+
"gb" => "United Kingdom",
|
239
|
+
"us" => "United States",
|
240
|
+
"um" => "United States Minor Outlying Islands",
|
241
|
+
"uy" => "Uruguay",
|
242
|
+
"uz" => "Uzbekistan",
|
243
|
+
"vu" => "Vanuatu",
|
244
|
+
"ve" => "Venezuela, Bolivarian Republic of",
|
245
|
+
"vn" => "Viet Nam",
|
246
|
+
"vg" => "Virgin Islands, British",
|
247
|
+
"vi" => "Virgin Islands, U.S.",
|
248
|
+
"wf" => "Wallis and Futuna",
|
249
|
+
"eh" => "Western Sahara",
|
250
|
+
"ye" => "Yemen",
|
251
|
+
"zm" => "Zambia",
|
252
|
+
} unless const_defined?("COUNTRIES")
|
253
|
+
|
254
|
+
ISO_COUNTRIES_FOR_SELECT = COUNTRIES.invert unless const_defined?("ISO_COUNTRIES_FOR_SELECT")
|
255
|
+
COUNTRIES_FOR_SELECT = COUNTRIES.values unless const_defined?("COUNTRIES_FOR_SELECT")
|
256
|
+
end
|
@@ -0,0 +1,133 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
require 'action_view'
|
4
|
+
require 'country_select'
|
5
|
+
|
6
|
+
module ActionView
|
7
|
+
module Helpers
|
8
|
+
|
9
|
+
describe CountrySelect do
|
10
|
+
include TagHelper
|
11
|
+
|
12
|
+
class Walrus
|
13
|
+
attr_accessor :country_name
|
14
|
+
end
|
15
|
+
|
16
|
+
let(:walrus) { Walrus.new }
|
17
|
+
|
18
|
+
let!(:template) { ActionView::Base.new }
|
19
|
+
|
20
|
+
let(:select_tag) do
|
21
|
+
"<select id=\"walrus_country_name\" name=\"walrus[country_name]\">"
|
22
|
+
end
|
23
|
+
|
24
|
+
let(:selected_us_option) do
|
25
|
+
if defined?(Tags::Base)
|
26
|
+
content_tag(:option, 'United States', :selected => :selected, :value => "United States")
|
27
|
+
else
|
28
|
+
"<option value=\"United States\" selected=\"selected\">United States</option>"
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
let(:selected_iso_us_option) do
|
33
|
+
if defined?(Tags::Base)
|
34
|
+
content_tag(:option, 'United States', :selected => :selected, :value => 'us')
|
35
|
+
else
|
36
|
+
"<option value=\"us\" selected=\"selected\">United States</option>"
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
let(:builder) do
|
41
|
+
if defined?(Tags::Base)
|
42
|
+
FormBuilder.new(:walrus, walrus, template, {})
|
43
|
+
else
|
44
|
+
FormBuilder.new(:walrus, walrus, template, {}, Proc.new { })
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
context "iso codes disabled" do
|
49
|
+
describe "#country_select" do
|
50
|
+
let(:tag) { builder.country_select(:country_name) }
|
51
|
+
|
52
|
+
it "creates a select tag" do
|
53
|
+
tag.should include(select_tag)
|
54
|
+
end
|
55
|
+
|
56
|
+
it "creates option tags of the countries" do
|
57
|
+
::CountrySelect::COUNTRIES.each do |code,name|
|
58
|
+
tag.should include(content_tag(:option, name, :value => name))
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
it "selects the value of country_name" do
|
63
|
+
walrus.country_name = 'United States'
|
64
|
+
t = builder.country_select(:country_name)
|
65
|
+
t.should include(selected_us_option)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
describe "#priority_countries" do
|
70
|
+
let(:tag) { builder.country_select(:country_name, ['United States']) }
|
71
|
+
|
72
|
+
it "puts the countries at the top" do
|
73
|
+
tag.should include("#{select_tag}<option value=\"United States")
|
74
|
+
end
|
75
|
+
|
76
|
+
it "inserts a divider" do
|
77
|
+
tag.should include(">United States</option><option value=\"\" disabled=\"disabled\">-------------</option>")
|
78
|
+
end
|
79
|
+
|
80
|
+
it "does not mark two countries as selected" do
|
81
|
+
walrus.country_name = "United States"
|
82
|
+
str = <<-EOS.strip
|
83
|
+
</option>\n<option value="United States" selected="selected">United States</option>
|
84
|
+
EOS
|
85
|
+
tag.should_not include(str)
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
context "iso codes enabled" do
|
91
|
+
describe "#country_select" do
|
92
|
+
let(:tag) { builder.country_select(:country_name, nil, :iso_codes => true) }
|
93
|
+
|
94
|
+
it "creates a select tag" do
|
95
|
+
tag.should include(select_tag)
|
96
|
+
end
|
97
|
+
|
98
|
+
it "creates option tags of the countries" do
|
99
|
+
::CountrySelect::COUNTRIES.each do |code,name|
|
100
|
+
tag.should include(content_tag(:option, name, :value => code))
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
it "selects the value of country_name" do
|
105
|
+
walrus.country_name = 'us'
|
106
|
+
t = builder.country_select(:country_name, nil, :iso_codes => true)
|
107
|
+
t.should include(selected_iso_us_option)
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
describe "#priority_countries" do
|
112
|
+
let(:tag) { builder.country_select(:country_name, ['us'], :iso_codes => true) }
|
113
|
+
|
114
|
+
it "puts the countries at the top" do
|
115
|
+
tag.should include("#{select_tag}<option value=\"us")
|
116
|
+
end
|
117
|
+
|
118
|
+
it "inserts a divider" do
|
119
|
+
tag.should include(">United States</option><option value=\"\" disabled=\"disabled\">-------------</option>")
|
120
|
+
end
|
121
|
+
|
122
|
+
it "does not mark two countries as selected" do
|
123
|
+
walrus.country_name = "us"
|
124
|
+
str = <<-EOS.strip
|
125
|
+
</option>\n<option value="us" selected="selected">United States</option>
|
126
|
+
EOS
|
127
|
+
tag.should_not include(str)
|
128
|
+
end
|
129
|
+
end
|
130
|
+
end
|
131
|
+
end
|
132
|
+
end
|
133
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
# This file was generated by the `rspec --init` command. Conventionally, all
|
2
|
+
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
3
|
+
# Require this file using `require "spec_helper"` to ensure that it is only
|
4
|
+
# loaded once.
|
5
|
+
#
|
6
|
+
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
7
|
+
|
8
|
+
require 'pry'
|
9
|
+
|
10
|
+
RSpec.configure do |config|
|
11
|
+
config.treat_symbols_as_metadata_keys_with_true_values = true
|
12
|
+
config.run_all_when_everything_filtered = true
|
13
|
+
config.filter_run :focus
|
14
|
+
|
15
|
+
# Run specs in random order to surface order dependencies. If you find an
|
16
|
+
# order dependency and want to debug it, you can fix the order by providing
|
17
|
+
# the seed, which is printed after each run.
|
18
|
+
# --seed 1234
|
19
|
+
config.order = 'random'
|
20
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: country_select
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,8 +9,72 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
13
|
-
dependencies:
|
12
|
+
date: 2013-07-07 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rspec
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: actionpack
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: appraisal
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: pry
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
type: :development
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
14
78
|
description: Provides a simple helper to get an HTML select list of countries. The
|
15
79
|
list of countries comes from the ISO 3166 standard. While it is a relatively neutral
|
16
80
|
source of country names, it will still offend some users.
|
@@ -21,15 +85,29 @@ extensions: []
|
|
21
85
|
extra_rdoc_files: []
|
22
86
|
files:
|
23
87
|
- .gitignore
|
88
|
+
- .rspec
|
89
|
+
- .travis.yml
|
90
|
+
- Appraisals
|
91
|
+
- CHANGELOG.md
|
24
92
|
- Gemfile
|
25
93
|
- MIT-LICENSE
|
26
94
|
- README.md
|
27
95
|
- Rakefile
|
28
|
-
- VERSION
|
29
96
|
- country_select.gemspec
|
97
|
+
- gemfiles/actionpack3.0.gemfile
|
98
|
+
- gemfiles/actionpack3.0.gemfile.lock
|
99
|
+
- gemfiles/actionpack3.1.gemfile
|
100
|
+
- gemfiles/actionpack3.1.gemfile.lock
|
101
|
+
- gemfiles/actionpack3.2.gemfile
|
102
|
+
- gemfiles/actionpack3.2.gemfile.lock
|
103
|
+
- gemfiles/actionpack4.0.gemfile
|
104
|
+
- gemfiles/actionpack4.0.gemfile.lock
|
30
105
|
- lib/country_select.rb
|
106
|
+
- lib/country_select/countries.rb
|
31
107
|
- lib/country_select/version.rb
|
32
|
-
|
108
|
+
- spec/country_select_spec.rb
|
109
|
+
- spec/spec_helper.rb
|
110
|
+
homepage: https://github.com/stefanpenner/country_select
|
33
111
|
licenses: []
|
34
112
|
post_install_message:
|
35
113
|
rdoc_options: []
|
@@ -41,22 +119,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
41
119
|
- - ! '>='
|
42
120
|
- !ruby/object:Gem::Version
|
43
121
|
version: '0'
|
44
|
-
segments:
|
45
|
-
- 0
|
46
|
-
hash: -229501016986175763
|
47
122
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
48
123
|
none: false
|
49
124
|
requirements:
|
50
125
|
- - ! '>='
|
51
126
|
- !ruby/object:Gem::Version
|
52
127
|
version: '0'
|
53
|
-
segments:
|
54
|
-
- 0
|
55
|
-
hash: -229501016986175763
|
56
128
|
requirements: []
|
57
129
|
rubyforge_project: country_select
|
58
|
-
rubygems_version: 1.8.
|
130
|
+
rubygems_version: 1.8.25
|
59
131
|
signing_key:
|
60
132
|
specification_version: 3
|
61
133
|
summary: Country Select Plugin
|
62
|
-
test_files:
|
134
|
+
test_files:
|
135
|
+
- spec/country_select_spec.rb
|
136
|
+
- spec/spec_helper.rb
|
data/VERSION
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
0.1.0
|