nbrew-country_select 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,2 @@
1
+ pkg
2
+ nbrew-country_select.gemspec
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2008 Michael Koziarski
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.
@@ -0,0 +1,19 @@
1
+ CountrySelect
2
+ =============
3
+
4
+ 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.
5
+
6
+ Users are strongly advised to evaluate the suitability of this list given their user base.
7
+
8
+ * Added Country 2 Code abbreviations to select menu.
9
+
10
+ Example
11
+ =======
12
+
13
+ # Standard, full country names
14
+ country_select("user", "country_name")
15
+
16
+ # Two-character abbreviations as the select values
17
+ country_select("user", "country_abbreviation", [['United States','US']], {:country_code => 2})
18
+
19
+ Copyright (c) 2008 Michael Koziarski, released under the MIT license
@@ -0,0 +1,36 @@
1
+ require 'rake'
2
+ require 'rake/testtask'
3
+ require 'rake/rdoctask'
4
+
5
+ desc 'Generate documentation for the nbrew-country_select gem.'
6
+ Rake::RDocTask.new(:rdoc) do |rdoc|
7
+ rdoc.rdoc_dir = 'rdoc'
8
+ rdoc.title = 'NBrew-Country_Select'
9
+ rdoc.options << '--line-numbers' << '--inline-source'
10
+ rdoc.rdoc_files.include('README.md')
11
+ rdoc.rdoc_files.include('lib/**/*.rb')
12
+ end
13
+
14
+ desc 'Default: run unit tests.'
15
+ task :default => :test
16
+
17
+ desc 'Test the simple_time_select plugin.'
18
+ Rake::TestTask.new(:test) do |t|
19
+ t.libs << 'lib'
20
+ t.pattern = 'test/**/*_test.rb'
21
+ t.verbose = true
22
+ end
23
+
24
+ begin
25
+ require 'jeweler'
26
+ Jeweler::Tasks.new do |gemspec|
27
+ gemspec.name = "nbrew-country_select"
28
+ gemspec.summary = "A Country Select menu with support for country 2-character code abbreviations."
29
+ gemspec.description = "Country Select with 2-code support."
30
+ gemspec.email = "michael@koziarski.com"
31
+ gemspec.homepage = "http://github.com/nbrew/country_select"
32
+ gemspec.authors = ["Michael Koziarski"]
33
+ end
34
+ rescue LoadError
35
+ puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
36
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.1
@@ -0,0 +1,2 @@
1
+ # Install hook code here
2
+ puts "The list of countries provided by this plugin may offend some users. Please review it carefully before you use it"
@@ -0,0 +1,152 @@
1
+ # CountrySelect
2
+ module ActionView
3
+ module Helpers
4
+ module FormOptionsHelper
5
+ # Return select and option tags for the given object and method, using country_options_for_select to generate the list of option tags.
6
+ def country_select(object, method, priority_countries = nil, options = {}, html_options = {})
7
+ InstanceTag.new(object, method, self, options.delete(:object)).to_country_select_tag(priority_countries, options, html_options)
8
+ end
9
+ # Returns a string of option tags for pretty much any country in the world. Supply a country name as +selected+ to
10
+ # have it marked as the selected option tag. You can also supply an array of countries as +priority_countries+, so
11
+ # that they will be listed above the rest of the (long) list.
12
+ #
13
+ # NOTE: Only the option tags are returned, you have to wrap this call in a regular HTML select tag.
14
+ def country_options_for_select(selected = nil, priority_countries = nil, country_code='FULL')
15
+ country_options = ""
16
+
17
+ if priority_countries
18
+ country_options += options_for_select(priority_countries, selected)
19
+ country_options += "<option value=\"\" disabled=\"disabled\">-------------</option>\n"
20
+ end
21
+
22
+ return country_options + options_for_select( (country_code.to_i == 2) ? COUNTRIES_TWO_CODE : COUNTRIES, selected)
23
+ end
24
+ # All the countries included in the country_options output.
25
+ COUNTRIES = ["Afghanistan", "Aland Islands", "Albania", "Algeria", "American Samoa", "Andorra", "Angola",
26
+ "Anguilla", "Antarctica", "Antigua And Barbuda", "Argentina", "Armenia", "Aruba", "Australia", "Austria",
27
+ "Azerbaijan", "Bahamas", "Bahrain", "Bangladesh", "Barbados", "Belarus", "Belgium", "Belize", "Benin",
28
+ "Bermuda", "Bhutan", "Bolivia", "Bosnia and Herzegowina", "Botswana", "Bouvet Island", "Brazil",
29
+ "British Indian Ocean Territory", "Brunei Darussalam", "Bulgaria", "Burkina Faso", "Burundi", "Cambodia",
30
+ "Cameroon", "Canada", "Cape Verde", "Cayman Islands", "Central African Republic", "Chad", "Chile", "China",
31
+ "Christmas Island", "Cocos (Keeling) Islands", "Colombia", "Comoros", "Congo",
32
+ "Congo, the Democratic Republic of the", "Cook Islands", "Costa Rica", "Cote d'Ivoire", "Croatia", "Cuba",
33
+ "Cyprus", "Czech Republic", "Denmark", "Djibouti", "Dominica", "Dominican Republic", "Ecuador", "Egypt",
34
+ "El Salvador", "Equatorial Guinea", "Eritrea", "Estonia", "Ethiopia", "Falkland Islands (Malvinas)",
35
+ "Faroe Islands", "Fiji", "Finland", "France", "French Guiana", "French Polynesia",
36
+ "French Southern Territories", "Gabon", "Gambia", "Georgia", "Germany", "Ghana", "Gibraltar", "Greece", "Greenland", "Grenada", "Guadeloupe", "Guam", "Guatemala", "Guernsey", "Guinea",
37
+ "Guinea-Bissau", "Guyana", "Haiti", "Heard and McDonald Islands", "Holy See (Vatican City State)",
38
+ "Honduras", "Hong Kong", "Hungary", "Iceland", "India", "Indonesia", "Iran, Islamic Republic of", "Iraq",
39
+ "Ireland", "Isle of Man", "Israel", "Italy", "Jamaica", "Japan", "Jersey", "Jordan", "Kazakhstan", "Kenya",
40
+ "Kiribati", "Korea, Democratic People's Republic of", "Korea, Republic of", "Kuwait", "Kyrgyzstan",
41
+ "Lao People's Democratic Republic", "Latvia", "Lebanon", "Lesotho", "Liberia", "Libyan Arab Jamahiriya",
42
+ "Liechtenstein", "Lithuania", "Luxembourg", "Macao", "Macedonia, The Former Yugoslav Republic Of",
43
+ "Madagascar", "Malawi", "Malaysia", "Maldives", "Mali", "Malta", "Marshall Islands", "Martinique",
44
+ "Mauritania", "Mauritius", "Mayotte", "Mexico", "Micronesia, Federated States of", "Moldova, Republic of",
45
+ "Monaco", "Mongolia", "Montenegro", "Montserrat", "Morocco", "Mozambique", "Myanmar", "Namibia", "Nauru",
46
+ "Nepal", "Netherlands", "Netherlands Antilles", "New Caledonia", "New Zealand", "Nicaragua", "Niger",
47
+ "Nigeria", "Niue", "Norfolk Island", "Northern Mariana Islands", "Norway", "Oman", "Pakistan", "Palau",
48
+ "Palestinian Territory, Occupied", "Panama", "Papua New Guinea", "Paraguay", "Peru", "Philippines",
49
+ "Pitcairn", "Poland", "Portugal", "Puerto Rico", "Qatar", "Reunion", "Romania", "Russian Federation",
50
+ "Rwanda", "Saint Barthelemy", "Saint Helena", "Saint Kitts and Nevis", "Saint Lucia",
51
+ "Saint Pierre and Miquelon", "Saint Vincent and the Grenadines", "Samoa", "San Marino",
52
+ "Sao Tome and Principe", "Saudi Arabia", "Senegal", "Serbia", "Seychelles", "Sierra Leone", "Singapore",
53
+ "Slovakia", "Slovenia", "Solomon Islands", "Somalia", "South Africa",
54
+ "South Georgia and the South Sandwich Islands", "Spain", "Sri Lanka", "Sudan", "Suriname",
55
+ "Svalbard and Jan Mayen", "Swaziland", "Sweden", "Switzerland", "Syrian Arab Republic",
56
+ "Taiwan, Province of China", "Tajikistan", "Tanzania, United Republic of", "Thailand", "Timor-Leste",
57
+ "Togo", "Tokelau", "Tonga", "Trinidad and Tobago", "Tunisia", "Turkey", "Turkmenistan",
58
+ "Turks and Caicos Islands", "Tuvalu", "Uganda", "Ukraine", "United Arab Emirates", "United Kingdom",
59
+ "United States", "United States Minor Outlying Islands", "Uruguay", "Uzbekistan", "Vanuatu", "Venezuela",
60
+ "Viet Nam", "Virgin Islands, British", "Virgin Islands, U.S.", "Wallis and Futuna", "Western Sahara",
61
+ "Yemen", "Zambia", "Zimbabwe"] unless const_defined?("COUNTRIES")
62
+
63
+ COUNTRIES_TWO_CODE = [
64
+ ['Afghanistan', 'AF'], ['Albania', 'AL'], ['Algeria', 'DZ'], ['American Samoa', 'AS'], ['Andorra', 'AD'],
65
+ ['Angola', 'AO'], ['Anguilla', 'AI'], ['Antarctica', 'AQ'], ['Antigua and Barbuda', 'AG'], ['Argentina', 'AR'],
66
+ ['Armenia', 'AM'], ['Aruba', 'AW'], ['Australia', 'AU'], ['Austria', 'AT'], ['Azerbaidjan', 'AZ'],
67
+ ['Bahamas', 'BS'], ['Bahrain', 'BH'], ['Bangladesh', 'BD'], ['Barbados', 'BB'], ['Belarus', 'BY'],
68
+ ['Belgium', 'BE'], ['Belize', 'BZ'], ['Benin', 'BJ'], ['Bermuda', 'BM'], ['Bhutan', 'BT'],
69
+ ['Bolivia', 'BO'], ['Bosnia-Herzegovina', 'BA'], ['Botswana', 'BW'], ['Bouvet Island', 'BV'],
70
+ ['Brazil', 'BR'], ['British Indian Ocean Territory', 'IO'], ['Brunei Darussalam', 'BN'], ['Bulgaria', 'BG'],
71
+ ['Burkina Faso', 'BF'], ['Burundi', 'BI'], ['Cambodia', 'KH'], ['Cameroon', 'CM'], ['Canada','CA'], ['Cape Verde', 'CV'],
72
+ ['Cayman Islands', 'KY'], ['Central African Republic', 'CF'], ['Chad', 'TD'], ['Chile', 'CL'],
73
+ ['China', 'CN'], ['Christmas Island', 'CX'], ['Cocos (Keeling) Islands', 'CC'], ['Colombia', 'CO'],
74
+ ['Comoros', 'KM'], ['Congo', 'CG'], ['Cook Islands', 'CK'], ['Costa Rica', 'CR'], ['Croatia', 'HR'],
75
+ ['Cuba', 'CU'], ['Cyprus', 'CY'], ['Czech Republic', 'CZ'], ['Denmark', 'DK'], ['Djibouti', 'DJ'],
76
+ ['Dominica', 'DM'], ['Dominican Republic', 'DO'], ['East Timor', 'TP'], ['Ecuador', 'EC'],
77
+ ['Egypt', 'EG'], ['El Salvador', 'SV'], ['Equatorial Guinea', 'GQ'], ['Eritrea', 'ER'],
78
+ ['Estonia', 'EE'], ['Ethiopia', 'ET'], ['Falkland Islands', 'FK'], ['Faroe Islands', 'FO'],
79
+ ['Fiji', 'FJ'], ['Finland', 'FI'], ['Former Czechoslovakia', 'CS'], ['Former USSR', 'SU'],
80
+ ['France', 'FR'], ['France (European Territory)', 'FX'], ['French Guyana', 'GF'],
81
+ ['French Southern Territories', 'TF'], ['Gabon', 'GA'], ['Gambia', 'GM'], ['Georgia', 'GE'],
82
+ ['Germany', 'DE'], ['Ghana', 'GH'], ['Gibraltar', 'GI'], ['Great Britain', 'GB'],
83
+ ['Greece', 'GR'], ['Greenland', 'GL'], ['Grenada', 'GD'], ['Guadeloupe (French)', 'GP'],
84
+ ['Guam (USA)', 'GU'], ['Guatemala', 'GT'], ['Guinea', 'GN'],['Guinea Bissau', 'GW'],
85
+ ['Guyana', 'GY'],['Haiti', 'HT'],['Heard and McDonald Islands', 'HM'],['Honduras', 'HN'],
86
+ ['Hong Kong', 'HK'],['Hungary', 'HU'],['Iceland', 'IS'],['India', 'IN'],
87
+ ['Indonesia', 'ID'],['International', 'INT'],['Iran', 'IR'],['Iraq', 'IQ'],
88
+ ['Ireland', 'IE'],['Israel', 'IL'],['Italy', 'IT'],['Ivory Coast (Cote D&#39;Ivoire)', 'CI'],
89
+ ['Jamaica', 'JM'],['Japan', 'JP'],['Jordan', 'JO'],['Kazakhstan', 'KZ'],
90
+ ['Kenya', 'KE'],['Kiribati', 'KI'],['Kuwait', 'KW'],['Kyrgyzstan', 'KG'],
91
+ ['Laos', 'LA'],['Latvia', 'LV'],['Lebanon', 'LB'],['Lesotho', 'LS'],
92
+ ['Liberia', 'LR'],['Libya', 'LY'],['Liechtenstein', 'LI'],['Lithuania', 'LT'],
93
+ ['Luxembourg', 'LU'],['Macau', 'MO'],['Macedonia', 'MK'],['Madagascar', 'MG'],
94
+ ['Malawi', 'MW'],['Malaysia', 'MY'],['Maldives', 'MV'],['Mali', 'ML'],['Malta', 'MT'],
95
+ ['Marshall Islands', 'MH'],['Martinique (French)', 'MQ'],['Mauritania', 'MR'],
96
+ ['Mauritius', 'MU'],['Mayotte', 'YT'],['Mexico', 'MX'],['Micronesia', 'FM'],
97
+ ['Moldavia', 'MD'],['Monaco', 'MC'],['Mongolia', 'MN'],['Montserrat', 'MS'],
98
+ ['Morocco', 'MA'],['Mozambique', 'MZ'],['Myanmar', 'MM'],['Namibia', 'NA'],
99
+ ['Nauru', 'NR'],['Nepal', 'NP'],['Netherlands', 'NL'],['Netherlands Antilles', 'AN'],
100
+ ['Neutral Zone', 'NT'],['New Caledonia (French)', 'NC'],['New Zealand', 'NZ'],
101
+ ['Nicaragua', 'NI'],['Niger', 'NE'],['Nigeria', 'NG'],['Niue', 'NU'],
102
+ ['Norfolk Island', 'NF'],['North Korea', 'KP'],['Northern Mariana Islands', 'MP'],
103
+ ['Norway', 'NO'],['Oman', 'OM'],['Pakistan', 'PK'],['Palau', 'PW'],['Panama', 'PA'],
104
+ ['Papua New Guinea', 'PG'],['Paraguay', 'PY'],['Peru', 'PE'],['Philippines', 'PH'],
105
+ ['Pitcairn Island', 'PN'],['Poland', 'PL'],['Polynesia (French)', 'PF'],['Portugal', 'PT'],
106
+ ['Puerto Rico', 'PR'],['Qatar', 'QA'],['Reunion (French)', 'RE'],['Romania', 'RO'],
107
+ ['Russian Federation', 'RU'],['Rwanda', 'RW'],['S. Georgia & S. Sandwich Isls.', 'GS'],
108
+ ['Saint Helena', 'SH'],['Saint Kitts & Nevis Anguilla', 'KN'],['Saint Lucia', 'LC'],
109
+ ['Saint Pierre and Miquelon', 'PM'],['Saint Tome (Sao Tome) and Principe', 'ST'],
110
+ ['Saint Vincent & Grenadines', 'VC'],['Samoa', 'WS'],['San Marino', 'SM'],['Saudi Arabia', 'SA'],
111
+ ['Senegal', 'SN'],['Seychelles', 'SC'],['Sierra Leone', 'SL'],['Singapore', 'SG'],
112
+ ['Slovak Republic', 'SK'],['Slovenia', 'SI'],['Solomon Islands', 'SB'],['Somalia', 'SO'],
113
+ ['South Africa', 'ZA'],['South Korea', 'KR'],['Spain', 'ES'],['Sri Lanka', 'LK'],
114
+ ['Sudan', 'SD'],['Suriname', 'SR'],['Svalbard and Jan Mayen Islands', 'SJ'],
115
+ ['Swaziland', 'SZ'],['Sweden', 'SE'],['Switzerland', 'CH'],['Syria', 'SY'],['Tadjikistan', 'TJ'],
116
+ ['Taiwan', 'TW'],['Tanzania', 'TZ'],['Thailand', 'TH'],['Togo', 'TG'],['Tokelau', 'TK'],
117
+ ['Tonga', 'TO'],['Trinidad and Tobago', 'TT'],['Tunisia', 'TN'],['Turkey', 'TR'],
118
+ ['Turkmenistan', 'TM'],['Turks and Caicos Islands', 'TC'],['Tuvalu', 'TV'],['Uganda', 'UG'],
119
+ ['Ukraine', 'UA'],['United Arab Emirates', 'AE'],['United Kingdom', 'GB'],['United States','US'],
120
+ ['Uruguay', 'UY'],['USA Military', 'MIL'],['USA Minor Outlying Islands', 'UM'],
121
+ ['Uzbekistan', 'UZ'],['Vanuatu', 'VU'],['Vatican City State', 'VA'],
122
+ ['Venezuela', 'VE'],['Vietnam', 'VN'],['Virgin Islands (British)', 'VG'],
123
+ ['Virgin Islands (USA)', 'VI'],['Wallis and Futuna Islands', 'WF'],
124
+ ['Western Sahara', 'EH'],['Yemen', 'YE'],['Yugoslavia', 'YU'],['Zaire', 'ZR'],
125
+ ['Zambia', 'ZM'],['Zimbabwe', 'ZW']
126
+ ] unless const_defined?("COUNTRIES_TWO_CODE")
127
+
128
+ end
129
+
130
+ class InstanceTag
131
+ def to_country_select_tag(priority_countries, options, html_options)
132
+ html_options = html_options.stringify_keys
133
+ add_default_name_and_id(html_options)
134
+ value = value(object)
135
+ content_tag("select",
136
+ add_options(
137
+ country_options_for_select(value, priority_countries,
138
+ options[:country_code].presence || 'FULL'
139
+ ),
140
+ options, value
141
+ ), html_options
142
+ )
143
+ end
144
+ end
145
+
146
+ class FormBuilder
147
+ def country_select(method, priority_countries = nil, options = {}, html_options = {})
148
+ @template.country_select(@object_name, method, priority_countries, options.merge(:object => @object), html_options)
149
+ end
150
+ end
151
+ end
152
+ end
@@ -0,0 +1 @@
1
+ require 'country_select'
@@ -0,0 +1 @@
1
+ # Uninstall hook code here
metadata ADDED
@@ -0,0 +1,75 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: nbrew-country_select
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - Michael Koziarski
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-06-28 00:00:00 -07:00
19
+ default_executable:
20
+ dependencies: []
21
+
22
+ description: Country Select with 2-code support.
23
+ email: michael@koziarski.com
24
+ executables: []
25
+
26
+ extensions: []
27
+
28
+ extra_rdoc_files:
29
+ - README.md
30
+ files:
31
+ - .gitignore
32
+ - MIT-LICENSE
33
+ - README.md
34
+ - Rakefile
35
+ - VERSION
36
+ - install.rb
37
+ - lib/country_select.rb
38
+ - rails/init.rb
39
+ - uninstall.rb
40
+ has_rdoc: true
41
+ homepage: http://github.com/nbrew/country_select
42
+ licenses: []
43
+
44
+ post_install_message:
45
+ rdoc_options:
46
+ - --charset=UTF-8
47
+ require_paths:
48
+ - lib
49
+ required_ruby_version: !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ hash: 3
55
+ segments:
56
+ - 0
57
+ version: "0"
58
+ required_rubygems_version: !ruby/object:Gem::Requirement
59
+ none: false
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ hash: 3
64
+ segments:
65
+ - 0
66
+ version: "0"
67
+ requirements: []
68
+
69
+ rubyforge_project:
70
+ rubygems_version: 1.3.7
71
+ signing_key:
72
+ specification_version: 3
73
+ summary: A Country Select menu with support for country 2-character code abbreviations.
74
+ test_files: []
75
+