country_code_select 1.0.0

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/.gitignore ADDED
@@ -0,0 +1,5 @@
1
+ *.gem
2
+ .bundle
3
+ .DS_Store
4
+ Gemfile.lock
5
+ pkg/*
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source "http://rubygems.org"
2
+
3
+ gemspec
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 ADDED
@@ -0,0 +1,14 @@
1
+ == Country Code Select
2
+
3
+ A simple country code select helper. Works exactly the same as country_select but uses country codes instead.
4
+
5
+ country_code_select(:user, :country, [[ 'United States', 'US' ], [ 'Canada', 'CA' ]])
6
+
7
+ == Requirements
8
+
9
+ Rails 3+
10
+ Ruby 1.9.2+
11
+
12
+ == Copyright/License
13
+
14
+ Copyright (c) 2008 Russ Smith, released under the MIT license.
data/README.rdoc ADDED
@@ -0,0 +1,9 @@
1
+ == Country Code Select
2
+
3
+ A simple country code select helper. Works exactly the same as country_select but uses country codes instead.
4
+
5
+ country_code_select(:user, :country, [[ 'US', 'United States' ], [ 'CA', 'Canada' ]])
6
+
7
+ == Copyright/License
8
+
9
+ Copyright (c) 2008 Russ Smith, released under the MIT license.
data/Rakefile ADDED
@@ -0,0 +1,15 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake"
3
+ require "rspec/core/rake_task"
4
+
5
+ namespace :spec do
6
+ RSpec::Core::RakeTask.new(:normal) do |t|
7
+ t.pattern = "spec/**/*_spec.rb"
8
+ t.rcov = false
9
+ end
10
+ end
11
+
12
+ desc "RSpec tests"
13
+ task "spec" => "spec:normal"
14
+
15
+ task "default" => "spec"
@@ -0,0 +1,24 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "country_code_select/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "country_code_select"
7
+ s.version = CountryCodeSelect::VERSION
8
+ s.authors = ["Russ Smith (russ@bashme.org)"]
9
+ s.email = "russ@bashme.org"
10
+ s.homepage = "http://github.com/russ/country_code_select"
11
+ s.summary = "A simple country code select helper. Works exactly the same as country_select but uses country codes instead."
12
+ s.description = "A simple country code select helper. Works exactly the same as country_select but uses country codes instead."
13
+ s.rubyforge_project = "country_code_select"
14
+ s.files = `git ls-files`.split("\n")
15
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
16
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
17
+ s.require_paths = ["lib"]
18
+ s.add_dependency("activesupport", ">= 3.0")
19
+ s.add_development_dependency("rake")
20
+ s.add_development_dependency("rspec", "~> 2.8")
21
+ s.add_development_dependency("rspec-html-matchers")
22
+ s.add_development_dependency("rspec-action_view")
23
+ s.add_development_dependency("yard")
24
+ end
data/init.rb ADDED
@@ -0,0 +1 @@
1
+ require File.join(File.dirname(__FILE__), "lib", "country_code_select")
@@ -0,0 +1,8 @@
1
+ require "country_code_select/countries"
2
+ require "country_code_select/form_builder"
3
+ require "country_code_select/form_helpers"
4
+ require "country_code_select/instance_tag"
5
+
6
+ ActionView::Base.send(:include, CountryCodeSelect::FormHelpers)
7
+ ActionView::Helpers::InstanceTag.send(:include, CountryCodeSelect::InstanceTag)
8
+ ActionView::Helpers::FormBuilder.send(:include, CountryCodeSelect::FormBuilder)
@@ -0,0 +1,42 @@
1
+ module CountryCodeSelect
2
+ module Countries
3
+ COUNTRIES = [["Afghanistan", "AF"], ["Albania", "AL"], ["Algeria", "DZ"], ["American Samoa", "AS"], ["Andorra", "AD"], ["Angola", "AO"],
4
+ ["Anguilla", "AI"], ["Antarctica", "AQ"], ["Antigua and Barbuda", "AG"], ["Argentina", "AR"], ["Armenia", "AM"], ["Aruba", "AW"],
5
+ ["Australia", "AU"], ["Austria", "AT"], ["Azerbaidjan", "AZ"], ["Bahamas", "BS"], ["Bahrain", "BH"], ["Banglades", "BD"], ["Barbados", "BB"],
6
+ ["Belarus", "BY"], ["Belgium", "BE"], ["Belize", "BZ"], ["Benin", "BJ"], ["Bermuda", "BM"], ["Bolivia", "BO"], ["Bosnia-Herzegovina", "BA"],
7
+ ["Botswana", "BW"], ["Bouvet Island", "BV"], ["Brazil", "BR"], ["British Indian O. Terr.", "IO"], ["Brunei Darussalam", "BN"], ["Bulgaria", "BG"],
8
+ ["Burkina Faso", "BF"], ["Burundi", "BI"], ["Buthan", "BT"], ["Cambodia", "KH"], ["Cameroon", "CM"], ["Canada", "CA"], ["Cape Verde", "CV"],
9
+ ["Cayman Islands", "KY"], ["Central African Rep.", "CF"], ["Chad", "TD"], ["Chile", "CL"], ["China", "CN"], ["Christmas Island", "CX"],
10
+ ["Cocos (Keeling) Isl.", "CC"], ["Colombia", "CO"], ["Comoros", "KM"], ["Congo", "CG"], ["Cook Islands", "CK"], ["Costa Rica", "CR"],
11
+ ["Croatia", "HR"], ["Cuba", "CU"], ["Cyprus", "CY"], ["Czech Republic", "CZ"], ["Czechoslovakia", "CS"], ["Denmark", "DK"], ["Djibouti", "DJ"],
12
+ ["Dominica", "DM"], ["Dominican Republic", "DO"], ["East Timor", "TP"], ["Ecuador", "EC"], ["Egypt", "EG"], ["El Salvador", "SV"],
13
+ ["Equatorial Guinea", "GQ"], ["Estonia", "EE"], ["Ethiopia", "ET"], ["Falkland Isl.(UK)", "FK"], ["Faroe Islands", "FO"], ["Fiji", "FJ"],
14
+ ["Finland", "FI"], ["France", "FR"], ["France (European Ter.)", "FX"], ["French Southern Terr.", "TF"], ["Gabon", "GA"], ["Gambia", "GM"],
15
+ ["Georgia", "GE"], ["Germany", "DE"], ["Ghana", "GH"], ["Gibraltar", "GI"], ["Great Britain (UK)", "GB"], ["Greece", "GR"], ["Greenland", "GL"],
16
+ ["Grenada", "GD"], ["Guadeloupe (Fr.)", "GP"], ["Guam (US)", "GU"], ["Guatemala", "GT"], ["Guinea", "GN"], ["Guinea Bissau", "GW"],
17
+ ["Guyana", "GY"], ["Guyana (Fr.)", "GF"], ["Haiti", "HT"], ["Heard & McDonald Isl.", "HM"], ["Honduras", "HN"], ["Hong Kong", "HK"],
18
+ ["Hungary", "HU"], ["Iceland", "IS"], ["India", "IN"], ["Indonesia", "ID"], ["Iran", "IR"], ["Iraq", "IQ"], ["Ireland", "IE"], ["Israel", "IL"],
19
+ ["Italy", "IT"], ["Ivory Coast", "CI"], ["Jamaica", "JM"], ["Japan", "JP"], ["Jordan", "JO"], ["Kazachstan", "KZ"], ["Kenya", "KE"],
20
+ ["Kirgistan", "KG"], ["Kiribati", "KI"], ["Korea (North)", "KP"], ["Korea (South)", "KR"], ["Kuwait", "KW"], ["Laos", "LA"], ["Latvia", "LV"],
21
+ ["Lebanon", "LB"], ["Lesotho", "LS"], ["Liberia", "LR"], ["Libya", "LY"], ["Liechtenstein", "LI"], ["Lithuania", "LT"], ["Luxembourg", "LU"],
22
+ ["Macau", "MO"], ["Madagascar", "MG"], ["Malawi", "MW"], ["Malaysia", "MY"], ["Maldives", "MV"], ["Mali", "ML"], ["Malta", "MT"],
23
+ ["Marshall Islands", "MH"], ["Martinique (Fr.)", "MQ"], ["Mauritania", "MR"], ["Mauritius", "MU"], ["Mexico", "MX"], ["Micronesia", "FM"],
24
+ ["Moldavia", "MD"], ["Monaco", "MC"], ["Mongolia", "MN"], ["Montserrat", "MS"], ["Morocco", "MA"], ["Mozambique", "MZ"], ["Myanmar", "MM"],
25
+ ["Namibia", "NA"], ["Nauru", "NR"], ["Nepal", "NP"], ["Netherland Antilles", "AN"], ["Netherlands", "NL"], ["Neutral Zone", "NT"],
26
+ ["New Caledonia (Fr.)", "NC"], ["New Zealand", "NZ"], ["Nicaragua", "NI"], ["Niger", "NE"], ["Nigeria", "NG"], ["Niue", "NU"],
27
+ ["Norfolk Island", "NF"], ["Northern Mariana Isl.", "MP"], ["Norway", "NO"], ["Oman", "OM"], ["Pakistan", "PK"], ["Palau", "PW"],
28
+ ["Panama", "PA"], ["Papua New", "PG"], ["Paraguay", "PY"], ["Peru", "PE"], ["Philippines", "PH"], ["Pitcairn", "PN"], ["Poland", "PL"],
29
+ ["Polynesia (Fr.)", "PF"], ["Portugal", "PT"], ["Puerto Rico (US)", "PR"], ["Qatar", "QA"], ["Reunion (Fr.)", "RE"], ["Romania", "RO"],
30
+ ["Russian Federation", "RU"], ["Rwanda", "RW"], ["Saint Lucia", "LC"], ["Samoa", "WS"], ["San Marino", "SM"], ["Saudi Arabia", "SA"],
31
+ ["Senegal", "SN"], ["Seychelles", "SC"], ["Sierra Leone", "SL"], ["Singapore", "SG"], ["Slovak Republic", "SK"], ["Slovenia", "SI"],
32
+ ["Solomon Islands", "SB"], ["Somalia", "SO"], ["South Africa", "ZA"], ["Soviet Union", "SU"], ["Spain", "ES"], ["Sri Lanka", "LK"],
33
+ ["St. Helena", "SH"], ["St. Pierre & Miquelon", "PM"], ["St. Tome and Principe", "ST"], ["St.Kitts Nevis Anguilla", "KN"],
34
+ ["St.Vincent & Grenadines", "VC"], ["Sudan", "SD"], ["Suriname", "SR"], ["Svalbard & Jan Mayen Is", "SJ"], ["Swaziland", "SZ"], ["Sweden", "SE"],
35
+ ["Switzerland", "CH"], ["Syria", "SY"], ["Tadjikistan", "TJ"], ["Taiwan", "TW"], ["Tanzania", "TZ"], ["Thailand", "TH"], ["Togo", "TG"],
36
+ ["Tokelau", "TK"], ["Tonga", "TO"], ["Trinidad & Tobago", "TT"], ["Tunisia", "TN"], ["Turkey", "TR"], ["Turkmenistan", "TM"],
37
+ ["Turks & Caicos Islands", "TC"], ["Tuvalu", "TV"], ["Uganda", "UG"], ["Ukraine", "UA"], ["United Arab Emirates", "AE"], ["United Kingdom", "GB"],
38
+ ["United States", "US"], ["Uruguay", "UY"], ["US Minor outlying Isl.", "UM"], ["Uzbekistan", "UZ"], ["Vanuatu", "VU"], ["Vatican City State", "VA"],
39
+ ["Venezuela", "VE"], ["Vietnam", "VN"], ["Virgin Islands (British)", "VG"], ["Virgin Islands (US)", "VI"], ["Wallis & Futuna Islands", "WF"],
40
+ ["Western Sahara", "EH"], ["Yemen", "YE"], ["Yugoslavia", "YU"], ["Zaire", "ZR"], ["Zambia", "ZM"], ["Zimbabwe", "ZW"]]
41
+ end
42
+ end
@@ -0,0 +1,7 @@
1
+ module CountryCodeSelect
2
+ module FormBuilder
3
+ def country_code_select(method, priority_countries = nil, options = {})
4
+ @template.country_code_select(@object_name, method, priority_countries, options.merge(object: @object))
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ module CountryCodeSelect
2
+ module FormHelpers
3
+ def country_code_select(object_name, method, priority_countries = nil, options = {})
4
+ ActionView::Helpers::InstanceTag.new(object_name, method, self, options.delete(:object)).to_country_code_select_tag(priority_countries, options)
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,26 @@
1
+ module CountryCodeSelect
2
+ module InstanceTag
3
+ include Countries
4
+
5
+ def to_country_code_select_tag(priority_countries, options = {})
6
+ country_code_select(priority_countries, 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)
11
+ selected = object.send(@method_name)
12
+
13
+ countries = ""
14
+ if priority_countries
15
+ countries += options_for_select(priority_countries, selected)
16
+ countries += "<option value=\"\" disabled=\"disabled\">-------------</option>\n"
17
+ elsif options[:include_blank]
18
+ countries += "<option value=\"\">" + options[:include_blank] + "</options>\n"
19
+ countries += "<option value=\"\" disabled=\"disabled\">-------------</option>\n"
20
+ end
21
+
22
+ countries = countries + options_for_select(COUNTRIES, selected)
23
+ content_tag(:select, countries, options.merge(id: "#{@object_name}_#{@method_name}", :name => "#{@object_name}[#{@method_name}]"), false)
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,3 @@
1
+ module CountryCodeSelect
2
+ VERSION = "1.0.0"
3
+ end
@@ -0,0 +1,7 @@
1
+ require "spec_helper"
2
+
3
+ describe CountryCodeSelect::FormHelpers do
4
+ it "should include country_code_select method" do
5
+ ActionView::Helpers::FormBuilder.instance_methods.should include(:country_code_select)
6
+ end
7
+ end
@@ -0,0 +1,26 @@
1
+ require "spec_helper"
2
+
3
+ describe CountryCodeSelect::FormHelpers do
4
+ describe "country_code_select" do
5
+ include CountryCodeSelect::FormHelpers
6
+
7
+ before(:each) do
8
+ @user = mock("User", :country => nil)
9
+ end
10
+
11
+ it "should output a select field with countries" do
12
+ output = country_code_select(:user, :country)
13
+ output.should match(/select id="user_country"/)
14
+ end
15
+
16
+ it "should output a select field with priority countries" do
17
+ output = country_code_select(:user, :country, [ "US", 'United States' ])
18
+ output.should match(/option value="US"/)
19
+ end
20
+
21
+ it "should output a select field with passed attributes" do
22
+ output = country_code_select(:user, :country, [ "US", "United States" ], class: "custom_class")
23
+ output.should match(/select class="custom_class"/)
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,8 @@
1
+ $: << File.dirname(__FILE__) + "/../lib" << File.dirname(__FILE__)
2
+
3
+ require "rubygems"
4
+ require "active_support"
5
+ require "action_view"
6
+ require "rspec"
7
+
8
+ require "country_code_select"
metadata ADDED
@@ -0,0 +1,134 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: country_code_select
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Russ Smith (russ@bashme.org)
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-01-25 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: activesupport
16
+ requirement: &70217585749820 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '3.0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *70217585749820
25
+ - !ruby/object:Gem::Dependency
26
+ name: rake
27
+ requirement: &70217585749400 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *70217585749400
36
+ - !ruby/object:Gem::Dependency
37
+ name: rspec
38
+ requirement: &70217585748860 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ~>
42
+ - !ruby/object:Gem::Version
43
+ version: '2.8'
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *70217585748860
47
+ - !ruby/object:Gem::Dependency
48
+ name: rspec-html-matchers
49
+ requirement: &70217585748440 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: *70217585748440
58
+ - !ruby/object:Gem::Dependency
59
+ name: rspec-action_view
60
+ requirement: &70217585747980 !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ! '>='
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
66
+ type: :development
67
+ prerelease: false
68
+ version_requirements: *70217585747980
69
+ - !ruby/object:Gem::Dependency
70
+ name: yard
71
+ requirement: &70217585747560 !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ! '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: *70217585747560
80
+ description: A simple country code select helper. Works exactly the same as country_select
81
+ but uses country codes instead.
82
+ email: russ@bashme.org
83
+ executables: []
84
+ extensions: []
85
+ extra_rdoc_files: []
86
+ files:
87
+ - .gitignore
88
+ - Gemfile
89
+ - Gemfile.lock
90
+ - MIT-LICENSE
91
+ - README
92
+ - README.rdoc
93
+ - Rakefile
94
+ - country_code_select.gemspec
95
+ - init.rb
96
+ - lib/country_code_select.rb
97
+ - lib/country_code_select/countries.rb
98
+ - lib/country_code_select/form_builder.rb
99
+ - lib/country_code_select/form_helpers.rb
100
+ - lib/country_code_select/instance_tag.rb
101
+ - lib/country_code_select/version.rb
102
+ - spec/form_builder_spec.rb
103
+ - spec/form_helpers_spec.rb
104
+ - spec/spec_helper.rb
105
+ homepage: http://github.com/russ/country_code_select
106
+ licenses: []
107
+ post_install_message:
108
+ rdoc_options: []
109
+ require_paths:
110
+ - lib
111
+ required_ruby_version: !ruby/object:Gem::Requirement
112
+ none: false
113
+ requirements:
114
+ - - ! '>='
115
+ - !ruby/object:Gem::Version
116
+ version: '0'
117
+ required_rubygems_version: !ruby/object:Gem::Requirement
118
+ none: false
119
+ requirements:
120
+ - - ! '>='
121
+ - !ruby/object:Gem::Version
122
+ version: '0'
123
+ requirements: []
124
+ rubyforge_project: country_code_select
125
+ rubygems_version: 1.8.10
126
+ signing_key:
127
+ specification_version: 3
128
+ summary: A simple country code select helper. Works exactly the same as country_select
129
+ but uses country codes instead.
130
+ test_files:
131
+ - spec/form_builder_spec.rb
132
+ - spec/form_helpers_spec.rb
133
+ - spec/spec_helper.rb
134
+ has_rdoc: