country-select 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/lib/country_select.rb +84 -0
  2. metadata +49 -0
@@ -0,0 +1,84 @@
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)
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(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
+ end
63
+
64
+ class InstanceTag
65
+ def to_country_select_tag(priority_countries, options, html_options)
66
+ html_options = html_options.stringify_keys
67
+ add_default_name_and_id(html_options)
68
+ value = value(object)
69
+ content_tag("select",
70
+ add_options(
71
+ country_options_for_select(value, priority_countries),
72
+ options, value
73
+ ), html_options
74
+ )
75
+ end
76
+ end
77
+
78
+ class FormBuilder
79
+ def country_select(method, priority_countries = nil, options = {}, html_options = {})
80
+ @template.country_select(@object_name, method, priority_countries, options.merge(:object => @object), html_options)
81
+ end
82
+ end
83
+ end
84
+ end
metadata ADDED
@@ -0,0 +1,49 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: country-select
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.2
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Michael Koziarski
9
+ - James Dean Shepherd
10
+ autorequire:
11
+ bindir: bin
12
+ cert_chain: []
13
+ date: 2011-09-22 00:00:00.000000000 +01:00
14
+ default_executable:
15
+ dependencies: []
16
+ description: Provides a form helper to insert a country select box using the ISO 3166
17
+ country list
18
+ email: jamesds2007@gmail.com
19
+ executables: []
20
+ extensions: []
21
+ extra_rdoc_files: []
22
+ files:
23
+ - lib/country_select.rb
24
+ has_rdoc: true
25
+ homepage: http://github.com/jamesds/iso-3166-country-select
26
+ licenses: []
27
+ post_install_message:
28
+ rdoc_options: []
29
+ require_paths:
30
+ - lib
31
+ required_ruby_version: !ruby/object:Gem::Requirement
32
+ none: false
33
+ requirements:
34
+ - - ! '>='
35
+ - !ruby/object:Gem::Version
36
+ version: '0'
37
+ required_rubygems_version: !ruby/object:Gem::Requirement
38
+ none: false
39
+ requirements:
40
+ - - ! '>='
41
+ - !ruby/object:Gem::Version
42
+ version: '0'
43
+ requirements: []
44
+ rubyforge_project:
45
+ rubygems_version: 1.6.2
46
+ signing_key:
47
+ specification_version: 3
48
+ summary: Country select box
49
+ test_files: []