state_select_plugin 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,163 @@
1
+ # encoding: utf-8
2
+
3
+ module ActionView::Helpers::FormOptionsHelper
4
+
5
+ # Return select and option tags for the given object and method, using state_options_for_select to generate the list of option tags.
6
+ def state_select(object, method, country='US', options = {}, html_options = {})
7
+ ActionView::Helpers::InstanceTag.new(object, method, self, options.delete(:object)).to_state_select_tag(country, options, html_options)
8
+ end
9
+
10
+ # Returns a string of option tags for states in a country. Supply a state name as +selected+ to
11
+ # have it marked as the selected option tag.
12
+ #
13
+ # NOTE: Only the option tags are returned, you have to wrap this call in a regular HTML select tag.
14
+
15
+ def state_options_for_select(selected = nil, country = 'US')
16
+ state_options = "".html_safe
17
+ if country
18
+ state_options += options_for_select(eval(country.upcase+'_STATES'), selected)
19
+ end
20
+ return state_options
21
+ end
22
+
23
+ private
24
+
25
+ US_STATES = [
26
+ "Alabama", "Alaska", "Arizona", "Arkansas", "California", "Colorado",
27
+ "Connecticut", "Delaware", "Florida", "Georgia", "Hawaii", "Idaho",
28
+ "Illinois", "Indiana", "Iowa", "Kansas", "Kentucky", "Louisiana",
29
+ "Maine", "Maryland", "Massachusetts", "Michigan", "Minnesota",
30
+ "Mississippi", "Missouri", "Montana", "Nebraska", "Nevada",
31
+ "New Hampshire", "New Jersey", "New Mexico", "New York",
32
+ "North Carolina", "North Dakota", "Ohio", "Oklahoma", "Oregon",
33
+ "Pennsylvania", "Puerto Rico", "Rhode Island", "South Carolina",
34
+ "South Dakota", "Tennessee", "Texas", "Utah", "Vermont", "Virginia",
35
+ "Washington", "Washington D.C.", "West Virginia", "Wisconsin", "Wyoming"
36
+ ] unless const_defined?("US_STATES")
37
+
38
+ UK_STATES = [
39
+ "Avon", "Bedfordshire", "Berkshire", "Borders", "Buckinghamshire",
40
+ "Cambridgeshire", "Central", "Cheshire", "Cleveland", "Clwyd",
41
+ "Cornwall", "County Antrim", "County Armagh", "County Down",
42
+ "County Fermanagh", "County Londonderry", "County Tyrone", "Cumbria",
43
+ "Derbyshire", "Devon", "Dorset", "Dumfries and Galloway", "Durham",
44
+ "Dyfed", "East Sussex", "Essex", "Fife", "Gloucestershire", "Grampian",
45
+ "Greater Manchester", "Gwent", "Gwynedd County", "Hampshire",
46
+ "Herefordshire", "Hertfordshire", "Highlands and Islands",
47
+ "Humberside", "Isle of Wight", "Kent", "Lancashire", "Leicestershire",
48
+ "Lincolnshire", "Lothian", "Merseyside", "Mid Glamorgan", "Norfolk",
49
+ "North Yorkshire", "Northamptonshire", "Northumberland",
50
+ "Nottinghamshire", "Oxfordshire", "Powys", "Rutland", "Shropshire",
51
+ "Somerset", "South Glamorgan", "South Yorkshire", "Staffordshire",
52
+ "Strathclyde", "Suffolk", "Surrey", "Tayside", "Tyne and Wear",
53
+ "Warwickshire", "West Glamorgan", "West Midlands", "West Sussex",
54
+ "West Yorkshire", "Wiltshire", "Worcestershire"
55
+ ] unless const_defined?("UK_STATES")
56
+
57
+ INDIA_STATES = [
58
+ "Andhra Pradesh", "Arunachal Pradesh", "Assam", "Bihar",
59
+ "Chhattisgarh", "New Delhi", "Goa", "Gujarat", "Haryana",
60
+ "Himachal Pradesh", "Jammu and Kashmir", "Jharkhand", "Karnataka",
61
+ "Kerala", "Madhya Pradesh", "Maharashtra", "Manipur", "Meghalaya",
62
+ "Mizoram", "Nagaland", "Orissa", "Punjab", "Rajasthan", "Sikkim",
63
+ "Tamil Nadu", "Tripura", "Uttaranchal", "Uttar Pradesh", "West Bengal"
64
+ ] unless const_defined?("INDIA_STATES")
65
+
66
+ CANADA_STATES = [
67
+ "Alberta", "British Columbia", "Manitoba", "New Brunswick",
68
+ "Newfoundland", "Northwest Territories", "Nova Scotia", "Nunavut",
69
+ "Ontario", "Prince Edward Island", "Quebec", "Saskatchewan", "Yukon"
70
+ ] unless const_defined?("CANADA_STATES")
71
+
72
+ AUSTRALIA_STATES = [
73
+ "Australian Capital Territory", "New South Wales", "Northern Territory",
74
+ "Queensland", "South Australia", "Tasmania", "Victoria",
75
+ "Western Australia"
76
+ ] unless const_defined?("AUSTRALIA_STATES")
77
+
78
+ SPAIN_STATES = [
79
+ "Alava", "Albacete", "Alicante", "Almeria", "Asturias", "Avila",
80
+ "Badajoz", "Barcelona", "Burgos", "Caceres", "Cadiz", "Cantrabria",
81
+ "Castellon", "Ceuta", "Ciudad Real", "Cordoba", "Cuenca", "Girona",
82
+ "Granada", "Guadalajara", "Guipuzcoa", "Huelva", "Huesca",
83
+ "Islas Baleares", "Jaen", "La Coruna", "Leon", "Lleida", "Lugo",
84
+ "Madrid", "Malaga", "Melilla", "Murcia", "Navarra", "Ourense",
85
+ "Palencia", "Palmas, Las", "Pontevedra", "Rioja, La", "Salamanda",
86
+ "Santa Cruz de Tenerife", "Segovia", "Sevila", "Soria", "Tarragona",
87
+ "Teruel", "Toledo", "Valencia", "Valladolid", "Vizcaya", "Zamora",
88
+ "Zaragoza"
89
+ ] unless const_defined?("SPAIN_STATES")
90
+
91
+ UGANDA_STATES = [
92
+ "Abim", "Adjumani", "Amolatar", "Amuria", "Apac", "Arua", "Budaka",
93
+ "Bugiri", "Bukwa", "Bulisa", "Bundibugyo", "Bushenyi", "Busia", "Busiki",
94
+ "Butaleja", "Dokolo", "Gulu", "Hoima", "Ibanda", "Iganga", "Jinja",
95
+ "Kaabong", "Kabale", "Kabarole", "Kaberamaido", "Kabingo", "Kalangala",
96
+ "Kaliro", "Kampala", "Kamuli", "Kamwenge", "Kanungu", "Kapchorwa",
97
+ "Kasese", "Katakwi", "Kayunga", "Kibale", "Kiboga", "Kilak", "Kiruhura",
98
+ "Kisoro", "Kitgum", "Koboko", "Kotido", "Kumi", "Kyenjojo", "Lira",
99
+ "Luwero", "Manafwa", "Maracha", "Masaka", "Masindi", "Mayuge", "Mbale",
100
+ "Mbarara", "Mityana", "Moroto", "Moyo", "Mpigi", "Mubende", "Mukono",
101
+ "Nakapiripirit", "Nakaseke", "Nakasongola", "Nebbi", "Ntungamo", "Oyam",
102
+ "Pader", "Pallisa", "Rakai", "Rukungiri", "Sembabule", "Sironko",
103
+ "Soroti", "Tororo", "Wakiso", "Yumbe"
104
+ ] unless const_defined?("UGANDA_STATES")
105
+
106
+ FRANCE_STATES = [
107
+ "Alsace", "Aquitaine", "Auvergne", "Bourgogne", "Bretagne", "Centre",
108
+ "Champagne-Ardenne", "Corse", "Franche-Comte", "Ile-de-France",
109
+ "Languedoc-Roussillon", "Limousin", "Lorraine", "Midi-Pyrenees",
110
+ "Nord-Pas-de-Calais", "Basse-Normandie", "Haute-Normandie",
111
+ "Pays de la Loire", "Picardie", "Poitou-Charentes",
112
+ "Provence-Alpes-Cote d'Azur", "Rhone-Alpes"
113
+ ] unless const_defined?("FRANCE_STATES")
114
+
115
+ GERMANY_STATES = [
116
+ "Baden-Wurttemberg", "Bayern", "Berlin", "Brandenburg", "Bremen",
117
+ "Hamburg", "Hessen", "Mecklenburg-Vorpommern", "Niedersachsen",
118
+ "Nordrhein-Westfalen", "Rhineland-Pflaz", "Saarland", "Sachsen",
119
+ "Sachsen-Anhalt", "Schleswig-Holstein", "Thuringen"
120
+ ] unless const_defined?("GERMANY_STATES")
121
+
122
+ NETHERLANDS_STATES = [
123
+ "Drenthe", "Flevoland", "Friesland", "Gelderland", "Groningen",
124
+ "Limburg", "Noord-Brabant", "Noord-Holland", "Overijssel", "Utrecht",
125
+ "Zeeland", "Zuid-Holland"
126
+ ] unless const_defined?("NETHERLANDS_STATES")
127
+
128
+ MEXICO_STATES = [
129
+ "Aguascalientes", "Baja Californi", "Baja California Sur",
130
+ "Campeche", "Chiapas", "Chihuahua", "Coahuila", "Colima", "Durango",
131
+ "Guanajuato", "Guerrero", "Hidalgo", "Jalisco", "México", "Michoacán",
132
+ "Morelos", "Nayarit", "Nuevo León", "Oaxaca", "Puebla", "Querétaro",
133
+ "Quintana Roo", "San Luis Potosí", "Sinaloa", "Sonora", "Tabasco",
134
+ "Tamaulipas", "Tlaxcala", "Veracruz", "Yucatán", "Zacatecas"
135
+ ] unless const_defined?("MEXICO_STATES")
136
+
137
+ POLAND_STATES = [
138
+ "dolnośląskie", "kujawsko-pomorskie", "lubelskie", "lubuskie", "łódzkie",
139
+ "małopolskie", "mazowieckie", "opolskie", "podkarpackie", "podlaskie",
140
+ "pomorskie", "śląskie", "świętokrzyskie", "warmińsko-mazurskie",
141
+ "wielkopolskie", "zachodniopomorskie"
142
+ ] unless const_defined?("POLAND_STATES")
143
+ end
144
+
145
+ class ActionView::Helpers::InstanceTag
146
+
147
+
148
+ def to_state_select_tag(country, options, html_options)
149
+ html_options = html_options.stringify_keys
150
+ add_default_name_and_id(html_options)
151
+ value = value(object)
152
+ selected_value = options.has_key?(:selected) ? options[:selected] : value
153
+ content_tag("select", add_options(state_options_for_select(selected_value, country), options, value), html_options)
154
+ end
155
+ end
156
+
157
+
158
+ class ActionView::Helpers::FormBuilder
159
+ def state_select(method, country = 'US', options = {}, html_options = {})
160
+ @template.state_select(@object_name, method, country, options.merge(:object => @object), html_options)
161
+ end
162
+ end
163
+
@@ -0,0 +1,31 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = %q{state_select}
5
+ s.version = "0.1.0"
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
+ s.authors = ["Akhil Bansal"]
9
+ s.date = %q{2012-02-28}
10
+ s.description = %q{State select}
11
+ s.email = %q{bansalakhil30.10@gmail.com}
12
+ s.extra_rdoc_files = ["lib/state_select.rb"]
13
+ s.homepage = %q{http://github.com/bansalakhil/state_select}
14
+ s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "State_select", "--main", "README"]
15
+ s.rubyforge_project = %q{state_select}
16
+ s.summary = %q{State select}
17
+ s.files = `git ls-files`.split("\n")
18
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
+ s.require_paths = ["lib"]
21
+
22
+ if s.respond_to? :specification_version then
23
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
24
+ s.specification_version = 3
25
+
26
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
27
+ else
28
+ end
29
+ else
30
+ end
31
+ end
@@ -0,0 +1,8 @@
1
+ #require 'test/unit'
2
+ #
3
+ #class USStateSelectTest < Test::Unit::TestCase
4
+ # Replace this with your real tests.
5
+ # def test_this_plugin
6
+ # flunk
7
+ # end
8
+ #end
metadata ADDED
@@ -0,0 +1,100 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: state_select_plugin
3
+ version: !ruby/object:Gem::Version
4
+ hash: 25
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 1
10
+ version: 0.1.1
11
+ platform: ruby
12
+ authors:
13
+ - Gaurav Saini
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2012-04-19 00:00:00 +05:30
19
+ default_executable:
20
+ dependencies: []
21
+
22
+ description: State select plugin
23
+ email: gauravsaini2@gmail.com
24
+ executables: []
25
+
26
+ extensions: []
27
+
28
+ extra_rdoc_files:
29
+ - lib/state_select_plugin.rb
30
+ files:
31
+ - MIT-LICENSE
32
+ - README.md
33
+ - doc/classes/ActionView.html
34
+ - doc/classes/ActionView/Helpers.html
35
+ - doc/classes/ActionView/Helpers/FormBuilder.html
36
+ - doc/classes/ActionView/Helpers/FormBuilder.src/M000003.html
37
+ - doc/classes/ActionView/Helpers/FormOptionsHelper.html
38
+ - doc/classes/ActionView/Helpers/FormOptionsHelper.src/M000001.html
39
+ - doc/classes/ActionView/Helpers/FormOptionsHelper.src/M000002.html
40
+ - doc/classes/ActionView/Helpers/InstanceTag.html
41
+ - doc/classes/ActionView/Helpers/InstanceTag.src/M000004.html
42
+ - doc/created.rid
43
+ - doc/dot/f_0.dot
44
+ - doc/files/init_rb.html
45
+ - doc/files/install_rb.html
46
+ - doc/files/lib/state_select_rb.html
47
+ - doc/files/test/state_select_test_rb.html
48
+ - doc/fr_class_index.html
49
+ - doc/fr_file_index.html
50
+ - doc/fr_method_index.html
51
+ - doc/index.html
52
+ - doc/rdoc-style.css
53
+ - init.rb
54
+ - install.rb
55
+ - lib/state_select.rb
56
+ - state_select.gemspec
57
+ - test/state_select_test.rb
58
+ - lib/state_select_plugin.rb
59
+ has_rdoc: true
60
+ homepage: http://github.com/gauravsaini2/state_select
61
+ licenses: []
62
+
63
+ post_install_message:
64
+ rdoc_options:
65
+ - --line-numbers
66
+ - --inline-source
67
+ - --title
68
+ - State_select Plugin
69
+ - --main
70
+ - README
71
+ require_paths:
72
+ - lib
73
+ required_ruby_version: !ruby/object:Gem::Requirement
74
+ none: false
75
+ requirements:
76
+ - - ">="
77
+ - !ruby/object:Gem::Version
78
+ hash: 3
79
+ segments:
80
+ - 0
81
+ version: "0"
82
+ required_rubygems_version: !ruby/object:Gem::Requirement
83
+ none: false
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ hash: 11
88
+ segments:
89
+ - 1
90
+ - 2
91
+ version: "1.2"
92
+ requirements: []
93
+
94
+ rubyforge_project: state_select
95
+ rubygems_version: 1.3.7
96
+ signing_key:
97
+ specification_version: 3
98
+ summary: State select Plugin
99
+ test_files:
100
+ - test/state_select_test.rb