iso-country-select 0.1.1

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.
@@ -0,0 +1,54 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = "iso-country-select"
8
+ s.version = "0.1.1"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["mcasimir"]
12
+ s.date = "2012-08-17"
13
+ s.description = "Localized country select helper for rails that stores ISO 3166-1 alpha-3 country codes instead of names"
14
+ s.email = "maurizio.cas@gmail.com"
15
+ s.extra_rdoc_files = [
16
+ "README.md"
17
+ ]
18
+ s.files = [
19
+ "Gemfile",
20
+ "Gemfile.lock",
21
+ "README.md",
22
+ "Rakefile",
23
+ "VERSION",
24
+ "config/locales/da.yml",
25
+ "config/locales/en.yml",
26
+ "config/locales/es.yml",
27
+ "config/locales/fr.yml",
28
+ "config/locales/it.yml",
29
+ "config/locales/ru.yml",
30
+ "iso-country-select.gemspec",
31
+ "lib/iso-country-select.rb"
32
+ ]
33
+ s.homepage = "http://github.com/mcasimir/kaminari-bootstrap"
34
+ s.licenses = ["MIT"]
35
+ s.require_paths = ["lib"]
36
+ s.rubygems_version = "1.8.24"
37
+ s.summary = "Localized country select helper for rails that stores ISO 3166-1 alpha-3 codes"
38
+
39
+ if s.respond_to? :specification_version then
40
+ s.specification_version = 3
41
+
42
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
43
+ s.add_runtime_dependency(%q<rails>, [">= 0"])
44
+ s.add_development_dependency(%q<jeweler>, [">= 0"])
45
+ else
46
+ s.add_dependency(%q<rails>, [">= 0"])
47
+ s.add_dependency(%q<jeweler>, [">= 0"])
48
+ end
49
+ else
50
+ s.add_dependency(%q<rails>, [">= 0"])
51
+ s.add_dependency(%q<jeweler>, [">= 0"])
52
+ end
53
+ end
54
+
@@ -0,0 +1,65 @@
1
+ # encoding: UTF-8
2
+
3
+ # Author:: Maurizio Casimirri (mailto:maurizio.cas@gmail.com)
4
+ # Copyright:: Copyright (c) 2012 Maurizio Casimirri
5
+ #
6
+ # Permission is hereby granted, free of charge, to any person obtaining
7
+ # a copy of this software and associated documentation files (the
8
+ # "Software"), to deal in the Software without restriction, including
9
+ # without limitation the rights to use, copy, modify, merge, publish,
10
+ # distribute, sublicense, and/or sell copies of the Software, and to
11
+ # permit persons to whom the Software is furnished to do so, subject to
12
+ # the following conditions:
13
+ #
14
+ # The above copyright notice and this permission notice shall be
15
+ # included in all copies or substantial portions of the Software.
16
+ #
17
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
21
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24
+
25
+ module ActionView
26
+ module Helpers
27
+ module FormOptionsHelper
28
+ def country_select(object, method, priority_countries = nil, options = {}, html_options = {})
29
+ InstanceTag.new(object, method, self, options.delete(:object)).to_country_select_tag(priority_countries, options, html_options)
30
+ end
31
+ def country_options_for_select(selected = nil, priority_countries = nil)
32
+ country_options = ""
33
+
34
+ if priority_countries
35
+ country_options += options_for_select(priority_countries, selected)
36
+ country_options += "<option value=\"\" disabled=\"disabled\">-------------</option>\n"
37
+ selected=nil if priority_countries.include?(selected)
38
+ end
39
+ return country_options + options_for_select(COUNTRIES, selected)
40
+ end
41
+
42
+ COUNTRIES = [["Afghanistan", "AFG"], ["Aland Islands", "ALA"], ["Albania", "ALB"], ["Algeria", "DZA"], ["American Samoa", "ASM"], ["Andorra", "AND"], ["Angola", "AGO"], ["Anguilla", "AIA"], ["Antarctica", "ATA"], ["Antigua and Barbuda", "ATG"], ["Argentina", "ARG"], ["Armenia", "ARM"], ["Aruba", "ABW"], ["Australia", "AUS"], ["Austria", "AUT"], ["Azerbaijan", "AZE"], ["Bahamas", "BHS"], ["Bahrain", "BHR"], ["Bangladesh", "BGD"], ["Barbados", "BRB"], ["Belarus", "BLR"], ["Belgium", "BEL"], ["Belize", "BLZ"], ["Benin", "BEN"], ["Bermuda", "BMU"], ["Bhutan", "BTN"], ["Bolivia, Plurinational State of", "BOL"], ["Bonaire, Sint Eustatius and Saba", "BES"], ["Bosnia and Herzegovina", "BIH"], ["Botswana", "BWA"], ["Bouvet Island", "BVT"], ["Brazil", "BRA"], ["British Indian Ocean Territory", "IOT"], ["Brunei Darussalam", "BRN"], ["Bulgaria", "BGR"], ["Burkina Faso", "BFA"], ["Burundi", "BDI"], ["Cambodia", "KHM"], ["Cameroon", "CMR"], ["Canada", "CAN"], ["Cape Verde", "CPV"], ["Cayman Islands", "CYM"], ["Central African Republic", "CAF"], ["Chad", "TCD"], ["Chile", "CHL"], ["China", "CHN"], ["Christmas Island", "CXR"], ["Cocos (Keeling) Islands", "CCK"], ["Colombia", "COL"], ["Comoros", "COM"], ["Congo", "COG"], ["Congo, the Democratic Republic of the", "COD"], ["Cook Islands", "COK"], ["Costa Rica", "CRI"], ["Cote d'Ivoire", "CIV"], ["Croatia", "HRV"], ["Cuba", "CUB"], ["Curaçao", "CUW"], ["Cyprus", "CYP"], ["Czech Republic", "CZE"], ["Denmark", "DNK"], ["Djibouti", "DJI"], ["Dominica", "DMA"], ["Dominican Republic", "DOM"], ["Ecuador", "ECU"], ["Egypt", "EGY"], ["El Salvador", "SLV"], ["Equatorial Guinea", "GNQ"], ["Eritrea", "ERI"], ["Estonia", "EST"], ["Ethiopia", "ETH"], ["Falkland Islands (Malvinas)", "FLK"], ["Faroe Islands", "FRO"], ["Fiji", "FJI"], ["Finland", "FIN"], ["France", "FRA"], ["French Guiana", "GUF"], ["French Polynesia", "PYF"], ["French Southern Territories", "ATF"], ["Gabon", "GAB"], ["Gambia", "GMB"], ["Georgia", "GEO"], ["Germany", "DEU"], ["Ghana", "GHA"], ["Gibraltar", "GIB"], ["Greece", "GRC"], ["Greenland", "GRL"], ["Grenada", "GRD"], ["Guadeloupe", "GLP"], ["Guam", "GUM"], ["Guatemala", "GTM"], ["Guernsey", "GGY"], ["Guinea", "GIN"], ["Guinea-Bissau", "GNB"], ["Guyana", "GUY"], ["Haiti", "HTI"], ["Heard Island and McDonald Islands", "HMD"], ["Holy See (Vatican City State)", "VAT"], ["Honduras", "HND"], ["Hong Kong", "HKG"], ["Hungary", "HUN"], ["Iceland", "ISL"], ["India", "IND"], ["Indonesia", "IDN"], ["Iran, Islamic Republic of", "IRN"], ["Iraq", "IRQ"], ["Ireland", "IRL"], ["Isle of Man", "IMN"], ["Israel", "ISR"], ["Italy", "ITA"], ["Jamaica", "JAM"], ["Japan", "JPN"], ["Jersey", "JEY"], ["Jordan", "JOR"], ["Kazakhstan", "KAZ"], ["Kenya", "KEN"], ["Kiribati", "KIR"], ["Korea, Democratic People's Republic of", "PRK"], ["Korea, Republic of", "KOR"], ["Kuwait", "KWT"], ["Kyrgyzstan", "KGZ"], ["Lao People's Democratic Republic", "LAO"], ["Latvia", "LVA"], ["Lebanon", "LBN"], ["Lesotho", "LSO"], ["Liberia", "LBR"], ["Libya", "LBY"], ["Liechtenstein", "LIE"], ["Lithuania", "LTU"], ["Luxembourg", "LUX"], ["Macao", "MAC"], ["Macedonia, the former Yugoslav Republic of", "MKD"], ["Madagascar", "MDG"], ["Malawi", "MWI"], ["Malaysia", "MYS"], ["Maldives", "MDV"], ["Mali", "MLI"], ["Malta", "MLT"], ["Marshall Islands", "MHL"], ["Martinique", "MTQ"], ["Mauritania", "MRT"], ["Mauritius", "MUS"], ["Mayotte", "MYT"], ["Mexico", "MEX"], ["Micronesia, Federated States of", "FSM"], ["Moldova, Republic of", "MDA"], ["Monaco", "MCO"], ["Mongolia", "MNG"], ["Montenegro", "MNE"], ["Montserrat", "MSR"], ["Morocco", "MAR"], ["Mozambique", "MOZ"], ["Myanmar", "MMR"], ["Namibia", "NAM"], ["Nauru", "NRU"], ["Nepal", "NPL"], ["Netherlands", "NLD"], ["New Caledonia", "NCL"], ["New Zealand", "NZL"], ["Nicaragua", "NIC"], ["Niger", "NER"], ["Nigeria", "NGA"], ["Niue", "NIU"], ["Norfolk Island", "NFK"], ["Northern Mariana Islands", "MNP"], ["Norway", "NOR"], ["Oman", "OMN"], ["Pakistan", "PAK"], ["Palau", "PLW"], ["Palestinian Territory, Occupied", "PSE"], ["Panama", "PAN"], ["Papua New Guinea", "PNG"], ["Paraguay", "PRY"], ["Peru", "PER"], ["Philippines", "PHL"], ["Pitcairn", "PCN"], ["Poland", "POL"], ["Portugal", "PRT"], ["Puerto Rico", "PRI"], ["Qatar", "QAT"], ["Reunion", "REU"], ["Romania", "ROU"], ["Russian Federation", "RUS"], ["Rwanda", "RWA"], ["Saint Barthélemy", "BLM"], ["Saint Helena, Ascension and Tristan da Cunha", "SHN"], ["Saint Kitts and Nevis", "KNA"], ["Saint Lucia", "LCA"], ["Saint Martin (French part)", "MAF"], ["Saint Pierre and Miquelon", "SPM"], ["Saint Vincent and the Grenadines", "VCT"], ["Samoa", "WSM"], ["San Marino", "SMR"], ["Sao Tome and Principe", "STP"], ["Saudi Arabia", "SAU"], ["Senegal", "SEN"], ["Serbia", "SRB"], ["Seychelles", "SYC"], ["Sierra Leone", "SLE"], ["Singapore", "SGP"], ["Sint Maarten (Dutch part)", "SXM"], ["Slovakia", "SVK"], ["Slovenia", "SVN"], ["Solomon Islands", "SLB"], ["Somalia", "SOM"], ["South Africa", "ZAF"], ["South Georgia and the South Sandwich Islands", "SGS"], ["South Sudan", "SSD"], ["Spain", "ESP"], ["Sri Lanka", "LKA"], ["Sudan", "SDN"], ["Suriname", "SUR"], ["Svalbard and Jan Mayen", "SJM"], ["Swaziland", "SWZ"], ["Sweden", "SWE"], ["Switzerland", "CHE"], ["Syrian Arab Republic", "SYR"], ["Taiwan, Province of China", "TWN"], ["Tajikistan", "TJK"], ["Tanzania, United Republic of", "TZA"], ["Thailand", "THA"], ["Timor-Leste", "TLS"], ["Togo", "TGO"], ["Tokelau", "TKL"], ["Tonga", "TON"], ["Trinidad and Tobago", "TTO"], ["Tunisia", "TUN"], ["Turkey", "TUR"], ["Turkmenistan", "TKM"], ["Turks and Caicos Islands", "TCA"], ["Tuvalu", "TUV"], ["Uganda", "UGA"], ["Ukraine", "UKR"], ["United Arab Emirates", "ARE"], ["United Kingdom", "GBR"], ["United States", "USA"], ["United States Minor Outlying Islands", "UMI"], ["Uruguay", "URY"], ["Uzbekistan", "UZB"], ["Vanuatu", "VUT"], ["Venezuela, Bolivarian Republic of", "VEN"], ["Viet Nam", "VNM"], ["Virgin Islands, British", "VGB"], ["Virgin Islands, U.S.", "VIR"], ["Wallis and Futuna", "WLF"], ["Western Sahara", "ESH"], ["Yemen", "YEM"], ["Zambia", "ZMB"], ["Zimbabwe", "ZWE"]] unless const_defined?("COUNTRIES")
43
+ end
44
+
45
+ class InstanceTag
46
+ def to_country_select_tag(priority_countries, options, html_options)
47
+ html_options = html_options.stringify_keys
48
+ add_default_name_and_id(html_options)
49
+ value = value(object)
50
+ content_tag("select",
51
+ add_options(
52
+ country_options_for_select(value, priority_countries),
53
+ options, value
54
+ ), html_options
55
+ )
56
+ end
57
+ end
58
+
59
+ class FormBuilder
60
+ def country_select(method, priority_countries = nil, options = {}, html_options = {})
61
+ @template.country_select(@object_name, method, priority_countries, options.merge(:object => @object), html_options)
62
+ end
63
+ end
64
+ end
65
+ end
metadata ADDED
@@ -0,0 +1,96 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: iso-country-select
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - mcasimir
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-08-17 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rails
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: jeweler
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ description: Localized country select helper for rails that stores ISO 3166-1 alpha-3
47
+ country codes instead of names
48
+ email: maurizio.cas@gmail.com
49
+ executables: []
50
+ extensions: []
51
+ extra_rdoc_files:
52
+ - README.md
53
+ files:
54
+ - Gemfile
55
+ - Gemfile.lock
56
+ - README.md
57
+ - Rakefile
58
+ - VERSION
59
+ - config/locales/da.yml
60
+ - config/locales/en.yml
61
+ - config/locales/es.yml
62
+ - config/locales/fr.yml
63
+ - config/locales/it.yml
64
+ - config/locales/ru.yml
65
+ - iso-country-select.gemspec
66
+ - lib/iso-country-select.rb
67
+ homepage: http://github.com/mcasimir/kaminari-bootstrap
68
+ licenses:
69
+ - MIT
70
+ post_install_message:
71
+ rdoc_options: []
72
+ require_paths:
73
+ - lib
74
+ required_ruby_version: !ruby/object:Gem::Requirement
75
+ none: false
76
+ requirements:
77
+ - - ! '>='
78
+ - !ruby/object:Gem::Version
79
+ version: '0'
80
+ segments:
81
+ - 0
82
+ hash: 3339919059121232840
83
+ required_rubygems_version: !ruby/object:Gem::Requirement
84
+ none: false
85
+ requirements:
86
+ - - ! '>='
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ requirements: []
90
+ rubyforge_project:
91
+ rubygems_version: 1.8.24
92
+ signing_key:
93
+ specification_version: 3
94
+ summary: Localized country select helper for rails that stores ISO 3166-1 alpha-3
95
+ codes
96
+ test_files: []