country_select 1.1.3 → 2.5.2
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 +7 -0
- data/.gitignore +3 -1
- data/.rspec +3 -0
- data/.travis.yml +31 -0
- data/CHANGELOG.md +69 -0
- data/Gemfile +7 -4
- data/Gemfile.lock +293 -0
- data/README.md +146 -14
- data/Rakefile +10 -1
- data/UPGRADING.md +69 -0
- data/country_select.gemspec +17 -11
- data/gemfiles/actionpack.edge.gemfile +15 -0
- data/gemfiles/actionpack.edge.gemfile.lock +309 -0
- data/gemfiles/actionpack3.2.gemfile +11 -0
- data/gemfiles/actionpack3.2.gemfile.lock +293 -0
- data/gemfiles/actionpack4.0.gemfile +11 -0
- data/gemfiles/actionpack4.0.gemfile.lock +282 -0
- data/gemfiles/actionpack4.1.gemfile +11 -0
- data/gemfiles/actionpack4.1.gemfile.lock +286 -0
- data/gemfiles/actionpack4.2.gemfile +12 -0
- data/gemfiles/actionpack4.2.gemfile.lock +310 -0
- data/lib/country_select/country_select_helper.rb +38 -0
- data/lib/country_select/formats.rb +7 -0
- data/lib/country_select/rails3/country_select_helper.rb +39 -0
- data/lib/country_select/tag_helper.rb +103 -0
- data/lib/country_select/version.rb +1 -1
- data/lib/country_select.rb +10 -101
- data/spec/country_select_spec.rb +232 -0
- data/spec/spec_helper.rb +98 -0
- metadata +134 -21
- data/VERSION +0 -1
|
@@ -0,0 +1,310 @@
|
|
|
1
|
+
PATH
|
|
2
|
+
remote: ../
|
|
3
|
+
specs:
|
|
4
|
+
country_select (2.5.1)
|
|
5
|
+
countries (~> 1.2.0)
|
|
6
|
+
sort_alphabetical (~> 1.0)
|
|
7
|
+
|
|
8
|
+
GEM
|
|
9
|
+
remote: https://rubygems.org/
|
|
10
|
+
specs:
|
|
11
|
+
actionpack (4.2.5.rc2)
|
|
12
|
+
actionview (= 4.2.5.rc2)
|
|
13
|
+
activesupport (= 4.2.5.rc2)
|
|
14
|
+
rack (~> 1.6)
|
|
15
|
+
rack-test (~> 0.6.2)
|
|
16
|
+
rails-dom-testing (~> 1.0, >= 1.0.5)
|
|
17
|
+
rails-html-sanitizer (~> 1.0, >= 1.0.2)
|
|
18
|
+
actionview (4.2.5.rc2)
|
|
19
|
+
activesupport (= 4.2.5.rc2)
|
|
20
|
+
builder (~> 3.1)
|
|
21
|
+
erubis (~> 2.7.0)
|
|
22
|
+
rails-dom-testing (~> 1.0, >= 1.0.5)
|
|
23
|
+
rails-html-sanitizer (~> 1.0, >= 1.0.2)
|
|
24
|
+
activesupport (4.2.5.rc2)
|
|
25
|
+
i18n (~> 0.7)
|
|
26
|
+
json (~> 1.7, >= 1.7.7)
|
|
27
|
+
minitest (~> 5.1)
|
|
28
|
+
thread_safe (~> 0.3, >= 0.3.4)
|
|
29
|
+
tzinfo (~> 1.1)
|
|
30
|
+
builder (3.2.2)
|
|
31
|
+
coderay (1.1.0)
|
|
32
|
+
countries (1.2.1)
|
|
33
|
+
currencies (~> 0.4.2)
|
|
34
|
+
i18n_data (~> 0.7.0)
|
|
35
|
+
currencies (0.4.2)
|
|
36
|
+
diff-lcs (1.2.5)
|
|
37
|
+
erubis (2.7.0)
|
|
38
|
+
ffi2-generators (0.1.1)
|
|
39
|
+
i18n (0.7.0)
|
|
40
|
+
i18n_data (0.7.0)
|
|
41
|
+
json (1.8.3)
|
|
42
|
+
loofah (2.0.3)
|
|
43
|
+
nokogiri (>= 1.5.9)
|
|
44
|
+
method_source (0.8.2)
|
|
45
|
+
mini_portile (0.6.2)
|
|
46
|
+
minitest (5.8.2)
|
|
47
|
+
nokogiri (1.6.6.2)
|
|
48
|
+
mini_portile (~> 0.6.0)
|
|
49
|
+
pry (0.10.3)
|
|
50
|
+
coderay (~> 1.1.0)
|
|
51
|
+
method_source (~> 0.8.1)
|
|
52
|
+
slop (~> 3.4)
|
|
53
|
+
psych (2.0.15)
|
|
54
|
+
racc (1.4.13)
|
|
55
|
+
rack (1.6.4)
|
|
56
|
+
rack-test (0.6.3)
|
|
57
|
+
rack (>= 1.0)
|
|
58
|
+
rails-deprecated_sanitizer (1.0.3)
|
|
59
|
+
activesupport (>= 4.2.0.alpha)
|
|
60
|
+
rails-dom-testing (1.0.7)
|
|
61
|
+
activesupport (>= 4.2.0.beta, < 5.0)
|
|
62
|
+
nokogiri (~> 1.6.0)
|
|
63
|
+
rails-deprecated_sanitizer (>= 1.0.1)
|
|
64
|
+
rails-html-sanitizer (1.0.2)
|
|
65
|
+
loofah (~> 2.0)
|
|
66
|
+
railties (4.2.5.rc2)
|
|
67
|
+
actionpack (= 4.2.5.rc2)
|
|
68
|
+
activesupport (= 4.2.5.rc2)
|
|
69
|
+
rake (>= 0.8.7)
|
|
70
|
+
thor (>= 0.18.1, < 2.0)
|
|
71
|
+
rake (10.4.2)
|
|
72
|
+
rspec (3.3.0)
|
|
73
|
+
rspec-core (~> 3.3.0)
|
|
74
|
+
rspec-expectations (~> 3.3.0)
|
|
75
|
+
rspec-mocks (~> 3.3.0)
|
|
76
|
+
rspec-core (3.3.2)
|
|
77
|
+
rspec-support (~> 3.3.0)
|
|
78
|
+
rspec-expectations (3.3.1)
|
|
79
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
|
80
|
+
rspec-support (~> 3.3.0)
|
|
81
|
+
rspec-mocks (3.3.2)
|
|
82
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
|
83
|
+
rspec-support (~> 3.3.0)
|
|
84
|
+
rspec-support (3.3.0)
|
|
85
|
+
rubysl (2.1.0)
|
|
86
|
+
rubysl-abbrev (~> 2.0)
|
|
87
|
+
rubysl-base64 (~> 2.0)
|
|
88
|
+
rubysl-benchmark (~> 2.0)
|
|
89
|
+
rubysl-bigdecimal (~> 2.0)
|
|
90
|
+
rubysl-cgi (~> 2.0)
|
|
91
|
+
rubysl-cgi-session (~> 2.0)
|
|
92
|
+
rubysl-cmath (~> 2.0)
|
|
93
|
+
rubysl-complex (~> 2.0)
|
|
94
|
+
rubysl-continuation (~> 2.0)
|
|
95
|
+
rubysl-coverage (~> 2.0)
|
|
96
|
+
rubysl-csv (~> 2.0)
|
|
97
|
+
rubysl-curses (~> 2.0)
|
|
98
|
+
rubysl-date (~> 2.0)
|
|
99
|
+
rubysl-delegate (~> 2.0)
|
|
100
|
+
rubysl-digest (~> 2.0)
|
|
101
|
+
rubysl-drb (~> 2.0)
|
|
102
|
+
rubysl-e2mmap (~> 2.0)
|
|
103
|
+
rubysl-english (~> 2.0)
|
|
104
|
+
rubysl-enumerator (~> 2.0)
|
|
105
|
+
rubysl-erb (~> 2.0)
|
|
106
|
+
rubysl-etc (~> 2.0)
|
|
107
|
+
rubysl-expect (~> 2.0)
|
|
108
|
+
rubysl-fcntl (~> 2.0)
|
|
109
|
+
rubysl-fiber (~> 2.0)
|
|
110
|
+
rubysl-fileutils (~> 2.0)
|
|
111
|
+
rubysl-find (~> 2.0)
|
|
112
|
+
rubysl-forwardable (~> 2.0)
|
|
113
|
+
rubysl-getoptlong (~> 2.0)
|
|
114
|
+
rubysl-gserver (~> 2.0)
|
|
115
|
+
rubysl-io-console (~> 2.0)
|
|
116
|
+
rubysl-io-nonblock (~> 2.0)
|
|
117
|
+
rubysl-io-wait (~> 2.0)
|
|
118
|
+
rubysl-ipaddr (~> 2.0)
|
|
119
|
+
rubysl-irb (~> 2.1)
|
|
120
|
+
rubysl-logger (~> 2.0)
|
|
121
|
+
rubysl-mathn (~> 2.0)
|
|
122
|
+
rubysl-matrix (~> 2.0)
|
|
123
|
+
rubysl-mkmf (~> 2.0)
|
|
124
|
+
rubysl-monitor (~> 2.0)
|
|
125
|
+
rubysl-mutex_m (~> 2.0)
|
|
126
|
+
rubysl-net-ftp (~> 2.0)
|
|
127
|
+
rubysl-net-http (~> 2.0)
|
|
128
|
+
rubysl-net-imap (~> 2.0)
|
|
129
|
+
rubysl-net-pop (~> 2.0)
|
|
130
|
+
rubysl-net-protocol (~> 2.0)
|
|
131
|
+
rubysl-net-smtp (~> 2.0)
|
|
132
|
+
rubysl-net-telnet (~> 2.0)
|
|
133
|
+
rubysl-nkf (~> 2.0)
|
|
134
|
+
rubysl-observer (~> 2.0)
|
|
135
|
+
rubysl-open-uri (~> 2.0)
|
|
136
|
+
rubysl-open3 (~> 2.0)
|
|
137
|
+
rubysl-openssl (~> 2.0)
|
|
138
|
+
rubysl-optparse (~> 2.0)
|
|
139
|
+
rubysl-ostruct (~> 2.0)
|
|
140
|
+
rubysl-pathname (~> 2.0)
|
|
141
|
+
rubysl-prettyprint (~> 2.0)
|
|
142
|
+
rubysl-prime (~> 2.0)
|
|
143
|
+
rubysl-profile (~> 2.0)
|
|
144
|
+
rubysl-profiler (~> 2.0)
|
|
145
|
+
rubysl-pstore (~> 2.0)
|
|
146
|
+
rubysl-pty (~> 2.0)
|
|
147
|
+
rubysl-rational (~> 2.0)
|
|
148
|
+
rubysl-resolv (~> 2.0)
|
|
149
|
+
rubysl-rexml (~> 2.0)
|
|
150
|
+
rubysl-rinda (~> 2.0)
|
|
151
|
+
rubysl-rss (~> 2.0)
|
|
152
|
+
rubysl-scanf (~> 2.0)
|
|
153
|
+
rubysl-securerandom (~> 2.0)
|
|
154
|
+
rubysl-set (~> 2.0)
|
|
155
|
+
rubysl-shellwords (~> 2.0)
|
|
156
|
+
rubysl-singleton (~> 2.0)
|
|
157
|
+
rubysl-socket (~> 2.0)
|
|
158
|
+
rubysl-stringio (~> 2.0)
|
|
159
|
+
rubysl-strscan (~> 2.0)
|
|
160
|
+
rubysl-sync (~> 2.0)
|
|
161
|
+
rubysl-syslog (~> 2.0)
|
|
162
|
+
rubysl-tempfile (~> 2.0)
|
|
163
|
+
rubysl-thread (~> 2.0)
|
|
164
|
+
rubysl-thwait (~> 2.0)
|
|
165
|
+
rubysl-time (~> 2.0)
|
|
166
|
+
rubysl-timeout (~> 2.0)
|
|
167
|
+
rubysl-tmpdir (~> 2.0)
|
|
168
|
+
rubysl-tsort (~> 2.0)
|
|
169
|
+
rubysl-un (~> 2.0)
|
|
170
|
+
rubysl-uri (~> 2.0)
|
|
171
|
+
rubysl-weakref (~> 2.0)
|
|
172
|
+
rubysl-webrick (~> 2.0)
|
|
173
|
+
rubysl-xmlrpc (~> 2.0)
|
|
174
|
+
rubysl-yaml (~> 2.0)
|
|
175
|
+
rubysl-zlib (~> 2.0)
|
|
176
|
+
rubysl-abbrev (2.0.4)
|
|
177
|
+
rubysl-base64 (2.0.0)
|
|
178
|
+
rubysl-benchmark (2.0.1)
|
|
179
|
+
rubysl-bigdecimal (2.0.2)
|
|
180
|
+
rubysl-cgi (2.0.1)
|
|
181
|
+
rubysl-cgi-session (2.0.1)
|
|
182
|
+
rubysl-cmath (2.0.0)
|
|
183
|
+
rubysl-complex (2.0.0)
|
|
184
|
+
rubysl-continuation (2.0.0)
|
|
185
|
+
rubysl-coverage (2.0.3)
|
|
186
|
+
rubysl-csv (2.0.2)
|
|
187
|
+
rubysl-english (~> 2.0)
|
|
188
|
+
rubysl-curses (2.0.1)
|
|
189
|
+
rubysl-date (2.0.9)
|
|
190
|
+
rubysl-delegate (2.0.1)
|
|
191
|
+
rubysl-digest (2.0.8)
|
|
192
|
+
rubysl-drb (2.0.1)
|
|
193
|
+
rubysl-e2mmap (2.0.0)
|
|
194
|
+
rubysl-english (2.0.0)
|
|
195
|
+
rubysl-enumerator (2.0.0)
|
|
196
|
+
rubysl-erb (2.0.2)
|
|
197
|
+
rubysl-etc (2.0.3)
|
|
198
|
+
ffi2-generators (~> 0.1)
|
|
199
|
+
rubysl-expect (2.0.0)
|
|
200
|
+
rubysl-fcntl (2.0.4)
|
|
201
|
+
ffi2-generators (~> 0.1)
|
|
202
|
+
rubysl-fiber (2.0.0)
|
|
203
|
+
rubysl-fileutils (2.0.3)
|
|
204
|
+
rubysl-find (2.0.1)
|
|
205
|
+
rubysl-forwardable (2.0.1)
|
|
206
|
+
rubysl-getoptlong (2.0.0)
|
|
207
|
+
rubysl-gserver (2.0.0)
|
|
208
|
+
rubysl-socket (~> 2.0)
|
|
209
|
+
rubysl-thread (~> 2.0)
|
|
210
|
+
rubysl-io-console (2.0.0)
|
|
211
|
+
rubysl-io-nonblock (2.0.0)
|
|
212
|
+
rubysl-io-wait (2.0.0)
|
|
213
|
+
rubysl-ipaddr (2.0.0)
|
|
214
|
+
rubysl-irb (2.1.1)
|
|
215
|
+
rubysl-e2mmap (~> 2.0)
|
|
216
|
+
rubysl-mathn (~> 2.0)
|
|
217
|
+
rubysl-thread (~> 2.0)
|
|
218
|
+
rubysl-logger (2.1.0)
|
|
219
|
+
rubysl-mathn (2.0.0)
|
|
220
|
+
rubysl-matrix (2.1.0)
|
|
221
|
+
rubysl-e2mmap (~> 2.0)
|
|
222
|
+
rubysl-mkmf (2.0.1)
|
|
223
|
+
rubysl-fileutils (~> 2.0)
|
|
224
|
+
rubysl-shellwords (~> 2.0)
|
|
225
|
+
rubysl-monitor (2.0.0)
|
|
226
|
+
rubysl-mutex_m (2.0.0)
|
|
227
|
+
rubysl-net-ftp (2.0.1)
|
|
228
|
+
rubysl-net-http (2.0.4)
|
|
229
|
+
rubysl-cgi (~> 2.0)
|
|
230
|
+
rubysl-erb (~> 2.0)
|
|
231
|
+
rubysl-singleton (~> 2.0)
|
|
232
|
+
rubysl-net-imap (2.0.1)
|
|
233
|
+
rubysl-net-pop (2.0.1)
|
|
234
|
+
rubysl-net-protocol (2.0.1)
|
|
235
|
+
rubysl-net-smtp (2.0.1)
|
|
236
|
+
rubysl-net-telnet (2.0.0)
|
|
237
|
+
rubysl-nkf (2.0.1)
|
|
238
|
+
rubysl-observer (2.0.0)
|
|
239
|
+
rubysl-open-uri (2.0.0)
|
|
240
|
+
rubysl-open3 (2.0.0)
|
|
241
|
+
rubysl-openssl (2.3.1)
|
|
242
|
+
rubysl-optparse (2.0.1)
|
|
243
|
+
rubysl-shellwords (~> 2.0)
|
|
244
|
+
rubysl-ostruct (2.0.4)
|
|
245
|
+
rubysl-pathname (2.1.0)
|
|
246
|
+
rubysl-prettyprint (2.0.3)
|
|
247
|
+
rubysl-prime (2.0.1)
|
|
248
|
+
rubysl-profile (2.0.0)
|
|
249
|
+
rubysl-profiler (2.0.1)
|
|
250
|
+
rubysl-pstore (2.0.0)
|
|
251
|
+
rubysl-pty (2.0.3)
|
|
252
|
+
rubysl-rational (2.0.1)
|
|
253
|
+
rubysl-resolv (2.1.2)
|
|
254
|
+
rubysl-rexml (2.0.4)
|
|
255
|
+
rubysl-rinda (2.0.1)
|
|
256
|
+
rubysl-rss (2.0.0)
|
|
257
|
+
rubysl-scanf (2.0.0)
|
|
258
|
+
rubysl-securerandom (2.0.0)
|
|
259
|
+
rubysl-set (2.0.1)
|
|
260
|
+
rubysl-shellwords (2.0.0)
|
|
261
|
+
rubysl-singleton (2.0.0)
|
|
262
|
+
rubysl-socket (2.0.1)
|
|
263
|
+
rubysl-stringio (2.0.0)
|
|
264
|
+
rubysl-strscan (2.0.0)
|
|
265
|
+
rubysl-sync (2.0.0)
|
|
266
|
+
rubysl-syslog (2.1.0)
|
|
267
|
+
ffi2-generators (~> 0.1)
|
|
268
|
+
rubysl-tempfile (2.0.1)
|
|
269
|
+
rubysl-thread (2.0.3)
|
|
270
|
+
rubysl-thwait (2.0.0)
|
|
271
|
+
rubysl-time (2.0.3)
|
|
272
|
+
rubysl-timeout (2.0.0)
|
|
273
|
+
rubysl-tmpdir (2.0.1)
|
|
274
|
+
rubysl-tsort (2.0.1)
|
|
275
|
+
rubysl-un (2.0.0)
|
|
276
|
+
rubysl-fileutils (~> 2.0)
|
|
277
|
+
rubysl-optparse (~> 2.0)
|
|
278
|
+
rubysl-uri (2.0.0)
|
|
279
|
+
rubysl-weakref (2.0.0)
|
|
280
|
+
rubysl-webrick (2.0.0)
|
|
281
|
+
rubysl-xmlrpc (2.0.0)
|
|
282
|
+
rubysl-yaml (2.1.0)
|
|
283
|
+
rubysl-zlib (2.0.1)
|
|
284
|
+
slop (3.6.0)
|
|
285
|
+
sort_alphabetical (1.0.2)
|
|
286
|
+
unicode_utils (>= 1.2.2)
|
|
287
|
+
thor (0.19.1)
|
|
288
|
+
thread_safe (0.3.5)
|
|
289
|
+
tzinfo (1.2.2)
|
|
290
|
+
thread_safe (~> 0.1)
|
|
291
|
+
unicode_utils (1.4.0)
|
|
292
|
+
wwtd (1.1.1)
|
|
293
|
+
|
|
294
|
+
PLATFORMS
|
|
295
|
+
ruby
|
|
296
|
+
|
|
297
|
+
DEPENDENCIES
|
|
298
|
+
actionpack (~> 4.2.0.beta1)
|
|
299
|
+
country_select!
|
|
300
|
+
pry (~> 0)
|
|
301
|
+
psych
|
|
302
|
+
racc
|
|
303
|
+
railties (~> 4.2.0.beta1)
|
|
304
|
+
rake
|
|
305
|
+
rspec (~> 3)
|
|
306
|
+
rubysl (~> 2.0)
|
|
307
|
+
wwtd
|
|
308
|
+
|
|
309
|
+
BUNDLED WITH
|
|
310
|
+
1.10.6
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
module ActionView
|
|
2
|
+
module Helpers
|
|
3
|
+
class FormBuilder
|
|
4
|
+
def country_select(method, priority_or_options = {}, options = {}, html_options = {})
|
|
5
|
+
if Hash === priority_or_options
|
|
6
|
+
html_options = options
|
|
7
|
+
options = priority_or_options
|
|
8
|
+
else
|
|
9
|
+
options[:priority_countries] = priority_or_options
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
@template.country_select(@object_name, method, objectify_options(options), @default_options.merge(html_options))
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
module FormOptionsHelper
|
|
17
|
+
def country_select(object, method, options = {}, html_options = {})
|
|
18
|
+
Tags::CountrySelect.new(object, method, self, options, html_options).render
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
module Tags
|
|
23
|
+
class CountrySelect < Base
|
|
24
|
+
include ::CountrySelect::TagHelper
|
|
25
|
+
|
|
26
|
+
def initialize(object_name, method_name, template_object, options, html_options)
|
|
27
|
+
@html_options = html_options
|
|
28
|
+
|
|
29
|
+
super(object_name, method_name, template_object, options)
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def render
|
|
33
|
+
select_content_tag(country_option_tags, @options, @html_options)
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
module ActionView
|
|
2
|
+
module Helpers
|
|
3
|
+
class FormBuilder
|
|
4
|
+
def country_select(method, priority_or_options = {}, options = {}, html_options = {})
|
|
5
|
+
if Hash === priority_or_options
|
|
6
|
+
html_options = options
|
|
7
|
+
options = priority_or_options
|
|
8
|
+
else
|
|
9
|
+
options[:priority_countries] = priority_or_options
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
@template.country_select(@object_name, method, objectify_options(options), @default_options.merge(html_options))
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
module FormOptionsHelper
|
|
17
|
+
def country_select(object, method, options = {}, html_options = {})
|
|
18
|
+
CountrySelect.new(object, method, self, options.delete(:object)).render(options, html_options)
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
class CountrySelect < InstanceTag
|
|
23
|
+
include ::CountrySelect::TagHelper
|
|
24
|
+
|
|
25
|
+
def render(options, html_options)
|
|
26
|
+
@options = options
|
|
27
|
+
@html_options = html_options
|
|
28
|
+
|
|
29
|
+
if self.respond_to?(:select_content_tag)
|
|
30
|
+
select_content_tag(country_option_tags, @options, @html_options)
|
|
31
|
+
else
|
|
32
|
+
html_options = @html_options.stringify_keys
|
|
33
|
+
add_default_name_and_id(html_options)
|
|
34
|
+
content_tag(:select, add_options(country_option_tags, options, value(object)), html_options)
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
end
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
module CountrySelect
|
|
2
|
+
class CountryNotFoundError < StandardError;end
|
|
3
|
+
module TagHelper
|
|
4
|
+
def country_option_tags
|
|
5
|
+
option_tags_options = {
|
|
6
|
+
:selected => @options.fetch(:selected) { value(@object) },
|
|
7
|
+
:disabled => @options[:disabled]
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
if priority_countries.present?
|
|
11
|
+
priority_countries_options = country_options_for(priority_countries, false)
|
|
12
|
+
|
|
13
|
+
option_tags = options_for_select(priority_countries_options, option_tags_options)
|
|
14
|
+
option_tags += html_safe_newline + options_for_select([priority_countries_divider], disabled: priority_countries_divider)
|
|
15
|
+
|
|
16
|
+
option_tags_options[:selected] = [option_tags_options[:selected]] unless option_tags_options[:selected].kind_of?(Array)
|
|
17
|
+
option_tags_options[:selected].delete_if{|selected| priority_countries_options.map(&:second).include?(selected)}
|
|
18
|
+
|
|
19
|
+
option_tags += html_safe_newline + options_for_select(country_options, option_tags_options)
|
|
20
|
+
else
|
|
21
|
+
option_tags = options_for_select(country_options, option_tags_options)
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
private
|
|
26
|
+
def locale
|
|
27
|
+
@options[:locale]
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def priority_countries
|
|
31
|
+
@options[:priority_countries]
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def priority_countries_divider
|
|
35
|
+
@options[:priority_countries_divider] || "-"*15
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def only_country_codes
|
|
39
|
+
@options[:only]
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def except_country_codes
|
|
43
|
+
@options[:except]
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def format
|
|
47
|
+
@options[:format] || :default
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def country_options
|
|
51
|
+
country_options_for(all_country_codes, true)
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
def all_country_codes
|
|
55
|
+
codes = ISO3166::Country.codes
|
|
56
|
+
|
|
57
|
+
if only_country_codes.present?
|
|
58
|
+
codes & only_country_codes
|
|
59
|
+
elsif except_country_codes.present?
|
|
60
|
+
codes - except_country_codes
|
|
61
|
+
else
|
|
62
|
+
codes
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
def country_options_for(country_codes, sorted=true)
|
|
67
|
+
I18n.with_locale(locale) do
|
|
68
|
+
country_list = country_codes.map do |code_or_name|
|
|
69
|
+
if country = ISO3166::Country.new(code_or_name)
|
|
70
|
+
code = country.alpha2
|
|
71
|
+
elsif country = ISO3166::Country.find_by_name(code_or_name)
|
|
72
|
+
code = country.first
|
|
73
|
+
country = ISO3166::Country.new(code)
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
unless country.present?
|
|
77
|
+
msg = "Could not find Country with string '#{code_or_name}'"
|
|
78
|
+
raise CountryNotFoundError.new(msg)
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
formatted_country = ::CountrySelect::FORMATS[format].call(country)
|
|
82
|
+
|
|
83
|
+
if formatted_country.is_a?(Array)
|
|
84
|
+
formatted_country
|
|
85
|
+
else
|
|
86
|
+
[formatted_country, code]
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
if sorted
|
|
92
|
+
country_list.sort_alphabetical
|
|
93
|
+
else
|
|
94
|
+
country_list
|
|
95
|
+
end
|
|
96
|
+
end
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
def html_safe_newline
|
|
100
|
+
"\n".html_safe
|
|
101
|
+
end
|
|
102
|
+
end
|
|
103
|
+
end
|
data/lib/country_select.rb
CHANGED
|
@@ -1,105 +1,14 @@
|
|
|
1
|
-
#
|
|
2
|
-
require 'country_select/version'
|
|
3
|
-
|
|
4
|
-
module ActionView
|
|
5
|
-
module Helpers
|
|
6
|
-
module FormOptionsHelper
|
|
7
|
-
# Return select and option tags for the given object and method, using country_options_for_select to generate the list of option tags.
|
|
8
|
-
def country_select(object, method, priority_countries = nil, options = {}, html_options = {})
|
|
9
|
-
# check if InstanceTag defined and accepts more than zero attributes in new method
|
|
10
|
-
if defined?(ActionView::Helpers::InstanceTag) && ActionView::Helpers::InstanceTag.instance_method(:initialize).arity != 0
|
|
11
|
-
InstanceTag.new(object, method, self, options.delete(:object)).to_country_select_tag(priority_countries, options, html_options)
|
|
12
|
-
else
|
|
13
|
-
CountrySelect.new(object, method, self, options).to_country_select_tag(priority_countries, options, html_options)
|
|
14
|
-
end
|
|
15
|
-
end
|
|
16
|
-
# Returns a string of option tags for pretty much any country in the world. Supply a country name as +selected+ to
|
|
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.
|
|
19
|
-
#
|
|
20
|
-
# NOTE: Only the option tags are returned, you have to wrap this call in a regular HTML select tag.
|
|
21
|
-
def country_options_for_select(selected = nil, priority_countries = nil)
|
|
22
|
-
country_options = "".html_safe
|
|
23
|
-
|
|
24
|
-
if priority_countries
|
|
25
|
-
country_options += options_for_select(priority_countries, selected)
|
|
26
|
-
country_options += "<option value=\"\" disabled=\"disabled\">-------------</option>\n".html_safe
|
|
27
|
-
# prevents selected from being included twice in the HTML which causes
|
|
28
|
-
# some browsers to select the second selected option (not priority)
|
|
29
|
-
# which makes it harder to select an alternative priority country
|
|
30
|
-
selected=nil if priority_countries.include?(selected)
|
|
31
|
-
end
|
|
1
|
+
# encoding: utf-8
|
|
32
2
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
# 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
|
-
end
|
|
3
|
+
require 'countries'
|
|
4
|
+
require 'sort_alphabetical'
|
|
74
5
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
add_default_name_and_id(html_options)
|
|
79
|
-
value = value(object)
|
|
80
|
-
content_tag("select",
|
|
81
|
-
add_options(
|
|
82
|
-
country_options_for_select(value, priority_countries),
|
|
83
|
-
options, value
|
|
84
|
-
), html_options
|
|
85
|
-
)
|
|
86
|
-
end
|
|
87
|
-
end
|
|
88
|
-
|
|
89
|
-
if defined?(ActionView::Helpers::InstanceTag) && ActionView::Helpers::InstanceTag.instance_method(:initialize).arity != 0
|
|
90
|
-
class InstanceTag
|
|
91
|
-
include ToCountrySelectTag
|
|
92
|
-
end
|
|
93
|
-
else
|
|
94
|
-
class CountrySelect < Tags::Base
|
|
95
|
-
include ToCountrySelectTag
|
|
96
|
-
end
|
|
97
|
-
end
|
|
6
|
+
require 'country_select/version'
|
|
7
|
+
require 'country_select/formats'
|
|
8
|
+
require 'country_select/tag_helper'
|
|
98
9
|
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
end
|
|
104
|
-
end
|
|
10
|
+
if defined?(ActionView::Helpers::Tags::Base)
|
|
11
|
+
require 'country_select/country_select_helper'
|
|
12
|
+
else
|
|
13
|
+
require 'country_select/rails3/country_select_helper'
|
|
105
14
|
end
|