english_county_select 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README +37 -0
- data/VERSION +1 -0
- data/init.rb +1 -0
- data/lib/english_county_select.rb +49 -0
- metadata +50 -0
data/README
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
# English County Select Tag
|
2
|
+
=============
|
3
|
+
|
4
|
+
Helper for Rails to list all English counties in a select tag.
|
5
|
+
Pretty much a modified copy of the country_select gem for rails.
|
6
|
+
URL: https://github.com/rails/country_select
|
7
|
+
|
8
|
+
## Installation
|
9
|
+
|
10
|
+
Install as a gem using
|
11
|
+
|
12
|
+
gem install english_county_select
|
13
|
+
|
14
|
+
Or put the following in your Gemfile
|
15
|
+
|
16
|
+
gem 'english_county_select'
|
17
|
+
|
18
|
+
## Example
|
19
|
+
|
20
|
+
Simple use supplying model and attribute as parameters:
|
21
|
+
|
22
|
+
english_county_select("user", "county_name")
|
23
|
+
|
24
|
+
or
|
25
|
+
|
26
|
+
form_for @user do |f|
|
27
|
+
f.english_county_select :county_name
|
28
|
+
end
|
29
|
+
|
30
|
+
|
31
|
+
## References
|
32
|
+
==============
|
33
|
+
http://www.carronmedia.com/uk-postal-counties-list/
|
34
|
+
http://en.wikipedia.org/wiki/List_of_counties_of_the_United_Kingdom
|
35
|
+
|
36
|
+
|
37
|
+
Copyright (c) 2013 Przemyslaw Bobak (Twitter: @bobek_balinek), under the WTFPL.
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|
data/init.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'english_county_select'
|
@@ -0,0 +1,49 @@
|
|
1
|
+
# english_county_select
|
2
|
+
module ActionView
|
3
|
+
module Helpers
|
4
|
+
module FormOptionsHelper
|
5
|
+
# Return select and option tags for the given object and method, using english_county_options_for_select to generate the list of option tags.
|
6
|
+
def english_county_select(object, method, priority_counties = nil, options = {}, html_options = {})
|
7
|
+
InstanceTag.new(object, method, self, options.delete(:object)).to_english_county_select_tag(priority_counties, options, html_options)
|
8
|
+
end
|
9
|
+
# Returns a string of option tags for pretty much any english_county in the world. Supply a english_county name as +selected+ to
|
10
|
+
# have it marked as the selected option tag. You can also supply an array of countries as +priority_counties+, 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 english_county_options_for_select(selected = nil, priority_counties = nil)
|
15
|
+
english_county_options = ""
|
16
|
+
|
17
|
+
if priority_counties
|
18
|
+
english_county_options += options_for_select(priority_counties, selected)
|
19
|
+
english_county_options += "<option value=\"\" disabled=\"disabled\">-------------</option>\n"
|
20
|
+
selected=nil if priority_counties.include?(selected)
|
21
|
+
end
|
22
|
+
|
23
|
+
return (english_county_options + grouped_options_for_select(COUNTIES, selected)).html_safe
|
24
|
+
end
|
25
|
+
# All the countries included in the english_county_options output.
|
26
|
+
COUNTIES = [ ["England", ["Avon", "Bedfordshire", "Berkshire", "Buckinghamshire", "Cambridgeshire", "Cheshire", "Cleveland", "Cornwall", "Cumbria", "Derbyshire", "Devon", "Dorset", "Durham", "East Sussex", "Essex", "Gloucestershire", "Hampshire", "Herefordshire", "Hertfordshire", "Isle of Wight", "Kent", "Lancashire", "Leicestershire", "Lincolnshire", "London", "Merseyside", "Middlesex", "Norfolk", "Northamptonshire", "Northumberland", "North Humberside", "North Yorkshire", "Nottinghamshire", "Oxfordshire", "Rutland", "Shropshire", "Somerset", "South Humberside", "South Yorkshire", "Staffordshire", "Suffolk", "Surrey", "Tyne and Wear", "Warwickshire", "West Midlands", "West Sussex", "West Yorkshire", "Wiltshire", "Worcestershire"]], ["Wales", ["Clwyd", "Dyfed", "Gwent", "Gwynedd", "Mid Glamorgan", "Powys", "South Glamorgan", "West Glamorgan"] ], ["Scotland", ["Aberdeenshire", "Angus", "Argyll", "Ayrshire", "Banffshire", "Berwickshire", "Bute", "Caithness", "Clackmannanshire", "Dumfriesshire", "Dunbartonshire", "East Lothian", "Fife", "Inverness-shire", "Kincardineshire", "Kinross-shire", "Kirkcudbrightshire", "Lanarkshire", "Midlothian", "Moray", "Nairnshire", "Orkney", "Peeblesshire", "Perthshire", "Renfrewshire", "Ross-shire", "Roxburghshire", "Selkirkshire", "Shetland", "Stirlingshire", "Sutherland", "West Lothian", "Wigtownshire"] ], ["Northern Ireland", ["Antrim", "Armagh", "Down", "Fermanagh", "Londonderry", "Tyrone"] ] ] unless const_defined?("COUNTIES")
|
27
|
+
end
|
28
|
+
|
29
|
+
class InstanceTag
|
30
|
+
def to_english_county_select_tag(priority_counties, options, html_options)
|
31
|
+
html_options = html_options.stringify_keys
|
32
|
+
add_default_name_and_id(html_options)
|
33
|
+
value = value(object)
|
34
|
+
content_tag("select",
|
35
|
+
add_options(
|
36
|
+
english_county_options_for_select(value, priority_counties),
|
37
|
+
options, value
|
38
|
+
), html_options
|
39
|
+
)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
class FormBuilder
|
44
|
+
def english_county_select(method, priority_counties = nil, options = {}, html_options = {})
|
45
|
+
@template.english_county_select(@object_name, method, priority_counties, options.merge(:object => @object), html_options)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
metadata
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: english_county_select
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Przemyslaw Bobak
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2009-11-28 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description: Rails select helper for English Counties
|
15
|
+
email: bobak.art@gmail.com
|
16
|
+
executables: []
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files:
|
19
|
+
- README
|
20
|
+
files:
|
21
|
+
- README
|
22
|
+
- VERSION
|
23
|
+
- init.rb
|
24
|
+
- lib/english_county_select.rb
|
25
|
+
homepage: http://github.com/bobekbalinek/English-County-Select
|
26
|
+
licenses: []
|
27
|
+
post_install_message:
|
28
|
+
rdoc_options:
|
29
|
+
- --charset=UTF-8
|
30
|
+
require_paths:
|
31
|
+
- lib
|
32
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ! '>='
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '0'
|
44
|
+
requirements: []
|
45
|
+
rubyforge_project:
|
46
|
+
rubygems_version: 1.8.24
|
47
|
+
signing_key:
|
48
|
+
specification_version: 3
|
49
|
+
summary: Rails select helper for English Counties
|
50
|
+
test_files: []
|