Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: gcorreaq/country_select
base: master
...
head fork: dgilperez/country_select
compare: master
Checking mergeability… Don't worry, you can still create the pull request.
  • 18 commits
  • 11 files changed
  • 0 commit comments
  • 4 contributors
Commits on Jan 23, 2012
@stefanpenner stefanpenner Gemification of country_select 69567dd
Commits on Mar 01, 2012
@oz oz html_safe the default options Strings
This gem broke while playing with:
    - rails ~>3.2
    - simple_form ~>2.0

The <option> tags are all unsafe and escaped, this is a simple enough fix
for that.
01b60a1
Commits on Mar 02, 2012
@stefanpenner stefanpenner Merge pull request #1 from oz/patch-1
html_safe the default options Strings (Fixes ~> Rails 3.2 related issues)
1b20654
@stefanpenner stefanpenner version bump 7ce2fb0
Commits on Apr 04, 2012
@stefanpenner stefanpenner improve docs 109615d
Commits on Jun 03, 2012
@stefanpenner stefanpenner VERSION BUMP 5847f20
Commits on Jul 17, 2012
@stefanpenner stefanpenner remove Netherlands Antilles 394163c
Commits on Jul 18, 2012
@stefanpenner stefanpenner Add "Curacao" and "Sint Maarten" b6747fd
@stefanpenner stefanpenner version bump 6ea54ce
Commits on Aug 26, 2012
@gcorreaq Now the values are the country codes 8c6e56c
@gcorreaq Revert "Now the values are the country codes"
This reverts commit 85a3aae.
a818cdd
@gcorreaq Now the list includes country codes
The list includes country codes, so the options select is generated
with country codes values
7f0cb39
@gcorreaq Fixed the formar of the data
Now is a hash instead of an array
0d2b267
@gcorreaq Country codes in downcase
Now, the country codes are in downcase for compatibility.
c3ef020
@dgilperez dgilperez fix typo in Herzegovina b10a30c
@dgilperez dgilperez adding country_name_from_code and inverse methods 63a7544
Commits on Sep 12, 2012
@dgilperez dgilperez translate country_select COUNTRIES to work with i18n-country-translat…
…ions gem
3a5e6fe
Commits on Oct 22, 2012
@dgilperez dgilperez sorting countries alphabetically, after being localized d2f9898
View
4 .gitignore
@@ -0,0 +1,4 @@
+*.gem
+.bundle
+Gemfile.lock
+pkg/*
View
4 Gemfile
@@ -0,0 +1,4 @@
+source "http://rubygems.org"
+
+# Specify your gem's dependencies in country_select.gemspec
+gemspec
View
14 README
@@ -1,14 +0,0 @@
-CountrySelect
-=============
-
-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.
-
-Users are strongly advised to evaluate the suitability of this list given their user base.
-
-Example
-=======
-
-country_select("user", "country_name")
-
-
-Copyright (c) 2008 Michael Koziarski, released under the MIT license
View
40 README.md
@@ -0,0 +1,40 @@
+Country-Select
+
+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 may
+still offend some users.
+
+Users are strongly advised to evaluate the suitability of this list given their user base.
+
+## Installation
+
+Install as a gem using
+
+ gem install country-select
+
+Or put the following in your Gemfile
+
+ gem 'country-select'
+
+## Example
+
+Simple use supplying model and attribute as parameters:
+
+ country_select("user", "country_name")
+
+Supplying priority countries to be placed at the top of the list:
+
+ country_select("user", "country_name", [ "United Kingdom", "France", "Germany" ])
+
+Specifying which country to be selected:
+United Kingdom will be selected.
+country_select("user", "country_name", [ "+United Kingdom+", "France", "Germany" ])
+
+Example in a Rails form:
+Full list, with New Zealand Australia and United Kingdom prioritized (New Zealand selected
+by default)
+<%= country_select(:player, :nationality, [ "+New Zealand+", "Australia", "United Kingdom" ])
+%>
+
+
+Copyright (c) 2008 Michael Koziarski, released under the MIT license
View
1  Rakefile
@@ -0,0 +1 @@
+require "bundler/gem_tasks"
View
24 country_select.gemspec
@@ -0,0 +1,24 @@
+# -*- encoding: utf-8 -*-
+$:.push File.expand_path("../lib", __FILE__)
+require "country_select/version"
+
+Gem::Specification.new do |s|
+ s.name = "country_select"
+ s.version = CountrySelect::VERSION
+ s.authors = ["Stefan Penner"]
+ s.email = ["stefan.penner@gmail.com"]
+ s.homepage = ""
+ s.summary = %q{Country Select Plugin}
+ 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.}
+
+ s.rubyforge_project = "country_select"
+
+ s.files = `git ls-files`.split("\n")
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
+ s.require_paths = ["lib"]
+
+ # specify any dependencies here; for example:
+ # s.add_development_dependency "rspec"
+ # s.add_runtime_dependency "rest-client"
+end
View
1  init.rb
@@ -1 +0,0 @@
-require 'country_select'
View
2  install.rb
@@ -1,2 +0,0 @@
-# Install hook code here
-puts "The list of countries provided by this plugin may offend some users. Please review it carefully before you use it"
View
316 lib/country_select.rb
@@ -1,4 +1,6 @@
# CountrySelect
+require 'country_select/version'
+
module ActionView
module Helpers
module FormOptionsHelper
@@ -12,59 +14,287 @@ def country_select(object, method, priority_countries = nil, options = {}, html_
#
# NOTE: Only the option tags are returned, you have to wrap this call in a regular HTML select tag.
def country_options_for_select(selected = nil, priority_countries = nil)
- country_options = ""
+ country_options = "".html_safe
if priority_countries
country_options += options_for_select(priority_countries, selected)
- country_options += "<option value=\"\" disabled=\"disabled\">-------------</option>\n"
+ country_options += "<option value=\"\" disabled=\"disabled\">-------------</option>\n".html_safe
# prevents selected from being included twice in the HTML which causes
# some browsers to select the second selected option (not priority)
# which makes it harder to select an alternative priority country
selected=nil if priority_countries.include?(selected)
end
- return country_options + options_for_select(COUNTRIES, selected)
+ localized_countries = COUNTRIES.map { |c| [I18n.t(c[1].upcase, :scope => :countries), c[1]] }.sort { |a,b| a[0] <=> b[0] }
+
+ return country_options + options_for_select(localized_countries, selected)
end
+
# All the countries included in the country_options output.
- COUNTRIES = ["Afghanistan", "Aland Islands", "Albania", "Algeria", "American Samoa", "Andorra", "Angola",
- "Anguilla", "Antarctica", "Antigua And Barbuda", "Argentina", "Armenia", "Aruba", "Australia", "Austria",
- "Azerbaijan", "Bahamas", "Bahrain", "Bangladesh", "Barbados", "Belarus", "Belgium", "Belize", "Benin",
- "Bermuda", "Bhutan", "Bolivia", "Bosnia and Herzegowina", "Botswana", "Bouvet Island", "Brazil",
- "British Indian Ocean Territory", "Brunei Darussalam", "Bulgaria", "Burkina Faso", "Burundi", "Cambodia",
- "Cameroon", "Canada", "Cape Verde", "Cayman Islands", "Central African Republic", "Chad", "Chile", "China",
- "Christmas Island", "Cocos (Keeling) Islands", "Colombia", "Comoros", "Congo",
- "Congo, the Democratic Republic of the", "Cook Islands", "Costa Rica", "Cote d'Ivoire", "Croatia", "Cuba",
- "Cyprus", "Czech Republic", "Denmark", "Djibouti", "Dominica", "Dominican Republic", "Ecuador", "Egypt",
- "El Salvador", "Equatorial Guinea", "Eritrea", "Estonia", "Ethiopia", "Falkland Islands (Malvinas)",
- "Faroe Islands", "Fiji", "Finland", "France", "French Guiana", "French Polynesia",
- "French Southern Territories", "Gabon", "Gambia", "Georgia", "Germany", "Ghana", "Gibraltar", "Greece", "Greenland", "Grenada", "Guadeloupe", "Guam", "Guatemala", "Guernsey", "Guinea",
- "Guinea-Bissau", "Guyana", "Haiti", "Heard and McDonald Islands", "Holy See (Vatican City State)",
- "Honduras", "Hong Kong", "Hungary", "Iceland", "India", "Indonesia", "Iran, Islamic Republic of", "Iraq",
- "Ireland", "Isle of Man", "Israel", "Italy", "Jamaica", "Japan", "Jersey", "Jordan", "Kazakhstan", "Kenya",
- "Kiribati", "Korea, Democratic People's Republic of", "Korea, Republic of", "Kuwait", "Kyrgyzstan",
- "Lao People's Democratic Republic", "Latvia", "Lebanon", "Lesotho", "Liberia", "Libyan Arab Jamahiriya",
- "Liechtenstein", "Lithuania", "Luxembourg", "Macao", "Macedonia, The Former Yugoslav Republic Of",
- "Madagascar", "Malawi", "Malaysia", "Maldives", "Mali", "Malta", "Marshall Islands", "Martinique",
- "Mauritania", "Mauritius", "Mayotte", "Mexico", "Micronesia, Federated States of", "Moldova, Republic of",
- "Monaco", "Mongolia", "Montenegro", "Montserrat", "Morocco", "Mozambique", "Myanmar", "Namibia", "Nauru",
- "Nepal", "Netherlands", "Netherlands Antilles", "New Caledonia", "New Zealand", "Nicaragua", "Niger",
- "Nigeria", "Niue", "Norfolk Island", "Northern Mariana Islands", "Norway", "Oman", "Pakistan", "Palau",
- "Palestinian Territory, Occupied", "Panama", "Papua New Guinea", "Paraguay", "Peru", "Philippines",
- "Pitcairn", "Poland", "Portugal", "Puerto Rico", "Qatar", "Reunion", "Romania", "Russian Federation",
- "Rwanda", "Saint Barthelemy", "Saint Helena", "Saint Kitts and Nevis", "Saint Lucia",
- "Saint Pierre and Miquelon", "Saint Vincent and the Grenadines", "Samoa", "San Marino",
- "Sao Tome and Principe", "Saudi Arabia", "Senegal", "Serbia", "Seychelles", "Sierra Leone", "Singapore",
- "Slovakia", "Slovenia", "Solomon Islands", "Somalia", "South Africa",
- "South Georgia and the South Sandwich Islands", "Spain", "Sri Lanka", "Sudan", "Suriname",
- "Svalbard and Jan Mayen", "Swaziland", "Sweden", "Switzerland", "Syrian Arab Republic",
- "Taiwan, Province of China", "Tajikistan", "Tanzania, United Republic of", "Thailand", "Timor-Leste",
- "Togo", "Tokelau", "Tonga", "Trinidad and Tobago", "Tunisia", "Turkey", "Turkmenistan",
- "Turks and Caicos Islands", "Tuvalu", "Uganda", "Ukraine", "United Arab Emirates", "United Kingdom",
- "United States", "United States Minor Outlying Islands", "Uruguay", "Uzbekistan", "Vanuatu", "Venezuela",
- "Viet Nam", "Virgin Islands, British", "Virgin Islands, U.S.", "Wallis and Futuna", "Western Sahara",
- "Yemen", "Zambia", "Zimbabwe"] unless const_defined?("COUNTRIES")
+ COUNTRIES = {
+ "Afghanistan" => "af",
+ "Aland Islands" => "ax",
+ "Albania" => "al",
+ "Algeria" => "dz",
+ "American Samoa" => "as",
+ "Andorra" => "ad",
+ "Angola" => "ao",
+ "Anguilla" => "ai",
+ "Antarctica" => "aq",
+ "Antigua And Barbuda" => "ag",
+ "Argentina" => "ar",
+ "Armenia" => "am",
+ "Aruba" => "aw",
+ "Australia" => "au",
+ "Austria" => "at",
+ "Azerbaijan" => "az",
+ "Bahamas" => "bs",
+ "Bahrain" => "bh",
+ "Bangladesh" => "bd",
+ "Barbados" => "bb",
+ "Belarus" => "by",
+ "Belgium" => "be",
+ "Belize" => "bz",
+ "Benin" => "bj",
+ "Bermuda" => "bm",
+ "Bhutan" => "bt",
+ "Bolivia, Plurinational State of" => "bo",
+ "Bonaire, Sint Eustatius and Saba" => "bq",
+ "Bosnia and Herzegovina" => "ba",
+ "Botswana" => "bw",
+ "Bouvet Island" => "bv",
+ "Brazil" => "br",
+ "British Indian Ocean Territory" => "io",
+ "Brunei Darussalam" => "bn",
+ "Bulgaria" => "bg",
+ "Burkina Faso" => "bf",
+ "Burundi" => "bi",
+ "Cambodia" => "kh",
+ "Cameroon" => "cm",
+ "Canada" => "ca",
+ "Cape Verde" => "cv",
+ "Cayman Islands" => "ky",
+ "Central African Republic" => "cf",
+ "Chad" => "td",
+ "Chile" => "cl",
+ "China" => "cn",
+ "Christmas Island" => "cx",
+ "Cocos (Keeling) Islands" => "cc",
+ "Colombia" => "co",
+ "Comoros" => "km",
+ "Congo" => "cg",
+ "Congo, the Democratic Republic of the" => "cd",
+ "Cook Islands" => "ck",
+ "Costa Rica" => "cr",
+ "Cote d'Ivoire" => "ci",
+ "Croatia" => "hr",
+ "Cuba" => "cu",
+ "Curacao" => "cw",
+ "Cyprus" => "cy",
+ "Czech Republic" => "cz",
+ "Denmark" => "dk",
+ "Djibouti" => "dj",
+ "Dominica" => "dm",
+ "Dominican Republic" => "do",
+ "Ecuador" => "ec",
+ "Egypt" => "eg",
+ "El Salvador" => "sv",
+ "Equatorial Guinea" => "gq",
+ "Eritrea" => "er",
+ "Estonia" => "ee",
+ "Ethiopia" => "et",
+ "Falkland Islands (Malvinas)" => "fk",
+ "Faroe Islands" => "fo",
+ "Fiji" => "fj",
+ "Finland" => "fi",
+ "France" => "fr",
+ "French Guiana" => "gf",
+ "French Polynesia" => "pf",
+ "French Southern Territories" => "tf",
+ "Gabon" => "ga",
+ "Gambia" => "gm",
+ "Georgia" => "ge",
+ "Germany" => "de",
+ "Ghana" => "gh",
+ "Gibraltar" => "gi",
+ "Greece" => "gr",
+ "Greenland" => "gl",
+ "Grenada" => "gd",
+ "Guadeloupe" => "gp",
+ "Guam" => "gu",
+ "Guatemala" => "gt",
+ "Guernsey" => "gg",
+ "Guinea" => "gn",
+ "Guinea-Bissau" => "gw",
+ "Guyana" => "gy",
+ "Haiti" => "ht",
+ "Heard and McDonald Islands" => "hm",
+ "Holy See (Vatican City State)" => "va",
+ "Honduras" => "hn",
+ "Hong Kong" => "hk",
+ "Hungary" => "hu",
+ "Iceland" => "is",
+ "India" => "in",
+ "Indonesia" => "id",
+ "Iran, Islamic Republic of" => "ir",
+ "Iraq" => "iq",
+ "Ireland" => "ie",
+ "Isle of Man" => "im",
+ "Israel" => "il",
+ "Italy" => "it",
+ "Jamaica" => "jm",
+ "Japan" => "jp",
+ "Jersey" => "je",
+ "Jordan" => "jo",
+ "Kazakhstan" => "kz",
+ "Kenya" => "ke",
+ "Kiribati" => "ki",
+ "Korea, Democratic People's Republic of" => "kp",
+ "Korea, Republic of" => "kr",
+ "Kuwait" => "kw",
+ "Kyrgyzstan" => "kg",
+ "Lao People's Democratic Republic" => "la",
+ "Latvia" => "lv",
+ "Lebanon" => "lb",
+ "Lesotho" => "ls",
+ "Liberia" => "lr",
+ "Libya" => "ly",
+ "Liechtenstein" => "li",
+ "Lithuania" => "lt",
+ "Luxembourg" => "lu",
+ "Macao" => "mo",
+ "Macedonia, The Former Yugoslav Republic Of" => "mk",
+ "Madagascar" => "mg",
+ "Malawi" => "mw",
+ "Malaysia" => "my",
+ "Maldives" => "mv",
+ "Mali" => "ml",
+ "Malta" => "mt",
+ "Marshall Islands" => "mh",
+ "Martinique" => "mq",
+ "Mauritania" => "mr",
+ "Mauritius" => "mu",
+ "Mayotte" => "yt",
+ "Mexico" => "mx",
+ "Micronesia, Federated States of" => "fm",
+ "Moldova, Republic of" => "md",
+ "Monaco" => "mc",
+ "Mongolia" => "mn",
+ "Montenegro" => "me",
+ "Montserrat" => "ms",
+ "Morocco" => "ma",
+ "Mozambique" => "mz",
+ "Myanmar" => "mm",
+ "Namibia" => "na",
+ "Nauru" => "nr",
+ "Nepal" => "np",
+ "Netherlands" => "nl",
+ "New Caledonia" => "nc",
+ "New Zealand" => "nz",
+ "Nicaragua" => "ni",
+ "Niger" => "ne",
+ "Nigeria" => "ng",
+ "Niue" => "nu",
+ "Norfolk Island" => "nf",
+ "Northern Mariana Islands" => "mp",
+ "Norway" => "no",
+ "Oman" => "om",
+ "Pakistan" => "pk",
+ "Palau" => "pw",
+ "Palestinian Territory, Occupied" => "ps",
+ "Panama" => "pa",
+ "Papua New Guinea" => "pg",
+ "Paraguay" => "py",
+ "Peru" => "pe",
+ "Philippines" => "ph",
+ "Pitcairn" => "pn",
+ "Poland" => "pl",
+ "Portugal" => "pt",
+ "Puerto Rico" => "pr",
+ "Qatar" => "qa",
+ "Reunion" => "re",
+ "Romania" => "ro",
+ "Russian Federation" => "ru",
+ "Rwanda" => "rw",
+ "Saint Barthelemy" => "bl",
+ "Saint Helena, Ascension and Tristan da Cunha" => "sh",
+ "Saint Kitts and Nevis" => "kn",
+ "Saint Lucia" => "lc",
+ "Saint Martin (French part)" => "mf",
+ "Saint Pierre and Miquelon" => "pm",
+ "Saint Vincent and the Grenadines" => "vc",
+ "Samoa" => "ws",
+ "San Marino" => "sm",
+ "Sao Tome and Principe" => "st",
+ "Saudi Arabia" => "sa",
+ "Senegal" => "sn",
+ "Serbia" => "rs",
+ "Seychelles" => "sc",
+ "Sierra Leone" => "sl",
+ "Singapore" => "sg",
+ "Sint Maarten (Dutch part)" => "sx",
+ "Slovakia" => "sk",
+ "Slovenia" => "si",
+ "Solomon Islands" => "sb",
+ "Somalia" => "so",
+ "South Africa" => "za",
+ "South Georgia and the South Sandwich Islands" => "gs",
+ "South Sudan" => "ss",
+ "Spain" => "es",
+ "Sri Lanka" => "lk",
+ "Sudan" => "sd",
+ "Suriname" => "sr",
+ "Svalbard and Jan Mayen" => "sj",
+ "Swaziland" => "sz",
+ "Sweden" => "se",
+ "Switzerland" => "ch",
+ "Syrian Arab Republic" => "sy",
+ "Taiwan, Province of China" => "tw",
+ "Tajikistan" => "tj",
+ "Tanzania, United Republic of" => "tz",
+ "Thailand" => "th",
+ "Timor-Leste" => "tl",
+ "Togo" => "tg",
+ "Tokelau" => "tk",
+ "Tonga" => "to",
+ "Trinidad and Tobago" => "tt",
+ "Tunisia" => "tn",
+ "Turkey" => "tr",
+ "Turkmenistan" => "tm",
+ "Turks and Caicos Islands" => "tc",
+ "Tuvalu" => "tv",
+ "Uganda" => "ug",
+ "Ukraine" => "ua",
+ "United Arab Emirates" => "ae",
+ "United Kingdom" => "gb",
+ "United States" => "us",
+ "United States Minor Outlying Islands" => "um",
+ "Uruguay" => "uy",
+ "Uzbekistan" => "uz",
+ "Vanuatu" => "vu",
+ "Venezuela, Bolivarian Republic of" => "ve",
+ "Viet Nam" => "vn",
+ "Virgin Islands, British" => "vg",
+ "Virgin Islands, U.S." => "vi",
+ "Wallis and Futuna" => "wf",
+ "Western Sahara" => "eh",
+ "Yemen" => "ye",
+ "Zambia" => "zm",
+ "Zimbabwe" => "zw"} unless const_defined?("COUNTRIES")
+
+ def country_codes
+ @@country_codes ||= COUNTRIES.values
+ end
+
+ def country_name_from_code(code)
+ COUNTRIES.key(code.to_s)
+ end
+
+ def country_code_from_name(name)
+ COUNTRIES[name.to_s]
+ end
end
-
+
class InstanceTag
def to_country_select_tag(priority_countries, options, html_options)
html_options = html_options.stringify_keys
@@ -78,11 +308,11 @@ def to_country_select_tag(priority_countries, options, html_options)
)
end
end
-
+
class FormBuilder
def country_select(method, priority_countries = nil, options = {}, html_options = {})
@template.country_select(@object_name, method, priority_countries, options.merge(:object => @object), html_options)
end
end
end
-end
+end
View
3  lib/country_select/version.rb
@@ -0,0 +1,3 @@
+module CountrySelect
+ VERSION = "1.0.1"
+end
View
1  uninstall.rb
@@ -1 +0,0 @@
-# Uninstall hook code here

No commit comments for this range

Something went wrong with that request. Please try again.