i18n_country_select 1.0.4

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.
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2008 Adam Meehan
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,39 @@
1
+ == Country Code Select
2
+
3
+ A simple country code select helper. Works exactly the same as country_select but uses country codes instead and has i18n translations for (some of) the country names.
4
+
5
+ == Requirements
6
+
7
+ * Rails 3+
8
+ * Ruby 1.9.2+
9
+ * https://github.com/onomojo/rails-i18n - Contains the country translations
10
+
11
+ == Installation
12
+ Put the following in your Gemfile
13
+
14
+ gem 'i18n_country_select', :git => 'git://github.com/onomojo/i18n_country_select.git'
15
+
16
+ == Example
17
+ Simple use supplying model and attribute as parameters:
18
+
19
+ country_code_select(:user, :country)
20
+
21
+ Supplying priority countries to be placed at the top of the list:
22
+
23
+ country_code_select(:user, :country, [[ 'US', 'United States' ], [ 'CA', 'Canada' ]])
24
+
25
+
26
+
27
+ == Contributors
28
+
29
+ * Brian McQuay from Onomojo
30
+ * Brad Carson from Base 3 Media
31
+ * Russ Smith
32
+
33
+
34
+
35
+
36
+
37
+ == Copyright/License
38
+
39
+ Copyright (c) 2008 Russ Smith, released under the MIT license.
@@ -0,0 +1,29 @@
1
+ module I18nCountrySelect
2
+ module Countries
3
+ COUNTRY_CODES = 'AF','AL','DZ','AS','AD','AO','AI','AQ','AG','AR',
4
+ 'AM','AW','AU','AT','AZ','BS','BH','BD','BB','BY',
5
+ 'BE','BZ','BJ','BM','BO','BA','BW','BV','BR','IO',
6
+ 'BN','BG','BF','BI','BT','KH','CM','CA','CV','KY',
7
+ 'CF','TD','CL','CN','CX','CC','CO','KM','CG','CK',
8
+ 'CR','HR','CU','CY','CZ','CS','DK','DJ','DM','DO',
9
+ 'EC','EG','SV','GQ','EE','ET','FK','FO','FJ','FI',
10
+ 'FR','FX','TF','GA','GM','GE','DE','GH','GI','GB',
11
+ 'GR','GL','GD','GP','GU','GT','GN','GW','GY','GF',
12
+ 'HT','HM','HN','HK','HU','IS','IN','ID','IR','IQ',
13
+ 'IE','IE','IL','IT','CI','JM','JP','JO','KZ','KE',
14
+ 'KG','KI','KP','KR','KW','LA','LV','LB','LS','LR',
15
+ 'LY','LI','LT','LU','LB','LS','LR','LY','LI','LT',
16
+ 'LU','MO','MG','MW','MY','MV','ML','MT','MH','MQ',
17
+ 'MR','MU','MX','FM','MD','MC','MN','MS','MA','MZ',
18
+ 'MM','NA','NR','NP','AN','NL','NC','NZ','NI','NE',
19
+ 'NG','NU','NF','MP','OM','PK','PW','PA','PG','PY',
20
+ 'PE','PH','PN','PL','PF','PT','PR','QA','RE','RO',
21
+ 'RU','RW','LC','WS','SM','SA','SN','SC','SL','SG',
22
+ 'SK','SI','SB','SO','ZA','ES','LK','SH','PM','ST',
23
+ 'KN','VC','SD','SR','SJ','SZ','SE','CH','SY','TJ',
24
+ 'TW','TZ','TH','TG','TK','TO','TT','TN','TR','TM',
25
+ 'TC','TV','UG','UA','AE','GB','US','UY','UM','UZ',
26
+ 'VU','VA','VE','VN','VG','VI','WF','EH','YE','ZM',
27
+ 'ZW'
28
+ end
29
+ end
@@ -0,0 +1,7 @@
1
+ module I18nCountrySelect
2
+ module FormBuilder
3
+ def country_code_select(method, priority_countries = nil, options = {}, html_options = {})
4
+ @template.country_code_select(@object_name, method, priority_countries, options.merge(object: @object), html_options)
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ module I18nCountrySelect
2
+ module FormHelpers
3
+ def country_code_select(object_name, method, priority_countries = nil, options = {}, html_options = {})
4
+ ActionView::Helpers::InstanceTag.new(object_name, method, self, options.delete(:object)).to_country_code_select_tag(priority_countries, options, html_options)
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,32 @@
1
+ module I18nCountrySelect
2
+ module InstanceTag
3
+ include Countries
4
+
5
+ def to_country_code_select_tag(priority_countries, options = {}, html_options = {})
6
+ country_code_select(priority_countries, options, html_options)
7
+ end
8
+
9
+ # Adapted from Rails country_select. Just uses country codes instead of full names.
10
+ def country_code_select(priority_countries, options, html_options)
11
+ selected = object.send(@method_name)
12
+
13
+ country_translations = COUNTRY_CODES.map{|code| [I18n.t(code, :scope => :countries), code]}
14
+
15
+ countries = ""
16
+ if priority_countries
17
+ countries += options_for_select(priority_countries, selected)
18
+ countries += "<option value=\"\" disabled=\"disabled\">-------------</option>\n"
19
+ elsif options[:include_blank]
20
+ countries += "<option value=\"\">" + options[:include_blank] + "</options>\n"
21
+ countries += "<option value=\"\" disabled=\"disabled\">-------------</option>\n"
22
+ end
23
+
24
+ countries = countries + options_for_select(country_translations, selected)
25
+
26
+ html_options = html_options.stringify_keys
27
+ add_default_name_and_id(html_options)
28
+
29
+ content_tag(:select, countries.html_safe, html_options)
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,3 @@
1
+ module I18nCountrySelect
2
+ VERSION = "1.0.3"
3
+ end
@@ -0,0 +1,8 @@
1
+ require "i18n_country_select/countries"
2
+ require "i18n_country_select/form_builder"
3
+ require "i18n_country_select/form_helpers"
4
+ require "i18n_country_select/instance_tag"
5
+
6
+ ActionView::Base.send(:include, I18nCountrySelect::FormHelpers)
7
+ ActionView::Helpers::InstanceTag.send(:include, I18nCountrySelect::InstanceTag)
8
+ ActionView::Helpers::FormBuilder.send(:include, I18nCountrySelect::FormBuilder)
metadata ADDED
@@ -0,0 +1,86 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: i18n_country_select
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.4
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Russ Smith (russ@bashme.org), Brian McQuay (brian@onomojo.com)
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-03-26 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: i18n-country-translations
16
+ requirement: &70238057029460 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: 0.0.1
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *70238057029460
25
+ - !ruby/object:Gem::Dependency
26
+ name: rails
27
+ requirement: &70238057029000 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: 3.0.0
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *70238057029000
36
+ - !ruby/object:Gem::Dependency
37
+ name: rspec-rails
38
+ requirement: &70238057028540 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: 2.7.0
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *70238057028540
47
+ description: A simple country code select helper that works with I18n translations.
48
+ Works exactly the same as country_select but uses country codes instead.
49
+ email: brian@onomojo.com
50
+ executables: []
51
+ extensions: []
52
+ extra_rdoc_files: []
53
+ files:
54
+ - lib/i18n_country_select/countries.rb
55
+ - lib/i18n_country_select/form_builder.rb
56
+ - lib/i18n_country_select/form_helpers.rb
57
+ - lib/i18n_country_select/instance_tag.rb
58
+ - lib/i18n_country_select/version.rb
59
+ - lib/i18n_country_select.rb
60
+ - README.md
61
+ - MIT-LICENSE
62
+ homepage: https://github.com/onomojo/i18n_country_select
63
+ licenses: []
64
+ post_install_message:
65
+ rdoc_options: []
66
+ require_paths:
67
+ - lib
68
+ required_ruby_version: !ruby/object:Gem::Requirement
69
+ none: false
70
+ requirements:
71
+ - - ! '>='
72
+ - !ruby/object:Gem::Version
73
+ version: '0'
74
+ required_rubygems_version: !ruby/object:Gem::Requirement
75
+ none: false
76
+ requirements:
77
+ - - ! '>='
78
+ - !ruby/object:Gem::Version
79
+ version: 1.3.5
80
+ requirements: []
81
+ rubyforge_project: ! '[none]'
82
+ rubygems_version: 1.8.10
83
+ signing_key:
84
+ specification_version: 3
85
+ summary: I18n country select helper
86
+ test_files: []