us_states_select 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/README ADDED
@@ -0,0 +1,32 @@
1
+ UsStates
2
+ ========
3
+
4
+ From http://svn.techno-weenie.net/projects/plugins/us_states/, updated
5
+ to run under rails 2.2.
6
+
7
+ To select "priority" states that show up at the top of the list, call
8
+ like so:
9
+
10
+ <%= us_state_select 'child', 'state', :priority => %w(TX CA) %>
11
+
12
+ To select the way states display option and value:
13
+
14
+ this (default):
15
+ <%= us_state_select 'child', 'state'%>
16
+
17
+ will yield this:
18
+ <option value="AK">Alaska</option>
19
+ ______
20
+ this:
21
+ <%= us_state_select 'child', 'state', :show => :full %>
22
+
23
+ will yield this:
24
+ <option value="Alaska">Alaska</option>
25
+
26
+ ______
27
+ Options are:
28
+
29
+ :full = <option value="Alaska">Alaska</option>
30
+ :full_abb = <option value="AK">Alaska</option>
31
+ :abbreviations = <option value="AK">AK</option>
32
+ ::abb_full_abb = <option value="AK">AK - Alaska</option>
data/Rakefile ADDED
@@ -0,0 +1,36 @@
1
+ require 'rake'
2
+ require 'rake/testtask'
3
+ require 'rake/rdoctask'
4
+
5
+ begin
6
+ require 'jeweler'
7
+ Jeweler::Tasks.new do |s|
8
+ s.name = "us_states_select"
9
+ s.summary = %Q{US State select Rails plugin}
10
+ s.homepage = "http://github.com/thincloud/us-state-select-plugin"
11
+ s.description = "US State select Rails plugin"
12
+ s.authors = ["Larry Sprock"]
13
+ end
14
+ rescue LoadError
15
+ puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
16
+ end
17
+
18
+ require 'rake/testtask'
19
+ Rake::TestTask.new(:test) do |t|
20
+ t.libs << 'lib' << 'test'
21
+ t.pattern = 'test/**/*_test.rb'
22
+ t.verbose = false
23
+ end
24
+
25
+ begin
26
+ require 'rcov/rcovtask'
27
+ Rcov::RcovTask.new do |t|
28
+ t.libs << 'test'
29
+ t.test_files = FileList['test/**/*_test.rb']
30
+ t.verbose = true
31
+ end
32
+ rescue LoadError
33
+ puts "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
34
+ end
35
+
36
+ task :default => :test
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 1.0.0
data/init.rb ADDED
@@ -0,0 +1 @@
1
+ require 'us_states_select'
@@ -0,0 +1,78 @@
1
+ module ActionView
2
+ module Helpers
3
+ module FormOptionsHelper
4
+ def us_state_options_for_select(selected = nil, us_state_options = {})
5
+ state_options = ""
6
+ priority_states = lambda { |state| us_state_options[:priority].include?(state.last) }
7
+ us_state_options[:show] = :full if us_state_options[:with_abbreviation]
8
+ states_label = case us_state_options[:show]
9
+ when :full_abb then lambda { |state| [state.first, state.last] }
10
+ when :full then lambda { |state| [state.first, state.first] }
11
+ when :abbreviations then lambda { |state| [state.last, state.last] }
12
+ when :abb_full_abb then lambda { |state| ["#{state.last} - #{state.first}", state.last] }
13
+ else lambda { |state| state }
14
+ end
15
+
16
+ if us_state_options[:include_blank]
17
+ state_options += "<option value=\"\">--</option>\n"
18
+ end
19
+
20
+ if us_state_options[:priority]
21
+ state_options += options_for_select(US_STATES.select(&priority_states).collect(&states_label), selected)
22
+ state_options += "<option value=\"\">--</option>\n"
23
+ end
24
+
25
+ if us_state_options[:priority] && us_state_options[:priority].include?(selected)
26
+ state_options += options_for_select(US_STATES.reject(&priority_states).collect(&states_label), selected)
27
+ else
28
+ state_options += options_for_select(US_STATES.collect(&states_label), selected)
29
+ end
30
+
31
+ return state_options
32
+ end
33
+
34
+ def us_state_select(object, method, us_state_options = {}, options = {}, html_options = {})
35
+ InstanceTag.new(object, method, self, options.delete(:object)).to_us_state_select_tag(us_state_options, options, html_options)
36
+ end
37
+
38
+ private
39
+ US_STATES = [["Alaska", "AK"], ["Alabama", "AL"], ["Arkansas", "AR"], ["Arizona", "AZ"],
40
+ ["California", "CA"], ["Colorado", "CO"], ["Connecticut", "CT"], ["District of Columbia", "DC"],
41
+ ["Delaware", "DE"], ["Florida", "FL"], ["Georgia", "GA"], ["Hawaii", "HI"], ["Iowa", "IA"],
42
+ ["Idaho", "ID"], ["Illinois", "IL"], ["Indiana", "IN"], ["Kansas", "KS"], ["Kentucky", "KY"],
43
+ ["Louisiana", "LA"], ["Massachusetts", "MA"], ["Maryland", "MD"], ["Maine", "ME"], ["Michigan", "MI"],
44
+ ["Minnesota", "MN"], ["Missouri", "MO"], ["Mississippi", "MS"], ["Montana", "MT"], ["North Carolina", "NC"],
45
+ ["North Dakota", "ND"], ["Nebraska", "NE"], ["New Hampshire", "NH"], ["New Jersey", "NJ"],
46
+ ["New Mexico", "NM"], ["Nevada", "NV"], ["New York", "NY"], ["Ohio", "OH"], ["Oklahoma", "OK"],
47
+ ["Oregon", "OR"], ["Pennsylvania", "PA"], ["Rhode Island", "RI"], ["South Carolina", "SC"], ["South Dakota", "SD"],
48
+ ["Tennessee", "TN"], ["Texas", "TX"], ["Utah", "UT"], ["Virginia", "VA"], ["Vermont", "VT"],
49
+ ["Washington", "WA"], ["Wisconsin", "WI"], ["West Virginia", "WV"], ["Wyoming", "WY"]] unless const_defined?("US_STATES")
50
+
51
+ end
52
+
53
+ class InstanceTag #:nodoc:
54
+ # lets the us_states plugin handle Rails 1.1.2 AND trunk
55
+ def value_with_compat(object=nil)
56
+ if method(:value_without_compat).arity == 1
57
+ value_without_compat(object)
58
+ else
59
+ value_without_compat
60
+ end
61
+ end
62
+ alias_method :value_without_compat, :value
63
+ alias_method :value, :value_with_compat
64
+
65
+ def to_us_state_select_tag(us_state_options, options, html_options)
66
+ html_options = html_options.stringify_keys
67
+ add_default_name_and_id(html_options)
68
+ content_tag("select", add_options(us_state_options_for_select(value(object), us_state_options), options, value(object)), html_options)
69
+ end
70
+ end
71
+
72
+ class FormBuilder
73
+ def us_state_select(method, us_state_options = {}, options = {}, html_options = {})
74
+ @template.us_state_select(@object_name, method, us_state_options, options.merge(:object => @object), html_options)
75
+ end
76
+ end
77
+ end
78
+ end
@@ -0,0 +1,41 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{us_states_select}
8
+ s.version = "1.0.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Larry Sprock"]
12
+ s.date = %q{2010-03-23}
13
+ s.description = %q{US State select Rails plugin}
14
+ s.extra_rdoc_files = [
15
+ "README"
16
+ ]
17
+ s.files = [
18
+ "README",
19
+ "Rakefile",
20
+ "VERSION",
21
+ "init.rb",
22
+ "lib/us_states_select.rb",
23
+ "us_states_select.gemspec"
24
+ ]
25
+ s.homepage = %q{http://github.com/thincloud/us-state-select-plugin}
26
+ s.rdoc_options = ["--charset=UTF-8"]
27
+ s.require_paths = ["lib"]
28
+ s.rubygems_version = %q{1.3.6}
29
+ s.summary = %q{US State select Rails plugin}
30
+
31
+ if s.respond_to? :specification_version then
32
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
33
+ s.specification_version = 3
34
+
35
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
36
+ else
37
+ end
38
+ else
39
+ end
40
+ end
41
+
metadata ADDED
@@ -0,0 +1,67 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: us_states_select
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 1
7
+ - 0
8
+ - 0
9
+ version: 1.0.0
10
+ platform: ruby
11
+ authors:
12
+ - Larry Sprock
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-03-23 00:00:00 -04:00
18
+ default_executable:
19
+ dependencies: []
20
+
21
+ description: US State select Rails plugin
22
+ email:
23
+ executables: []
24
+
25
+ extensions: []
26
+
27
+ extra_rdoc_files:
28
+ - README
29
+ files:
30
+ - README
31
+ - Rakefile
32
+ - VERSION
33
+ - init.rb
34
+ - lib/us_states_select.rb
35
+ - us_states_select.gemspec
36
+ has_rdoc: true
37
+ homepage: http://github.com/thincloud/us-state-select-plugin
38
+ licenses: []
39
+
40
+ post_install_message:
41
+ rdoc_options:
42
+ - --charset=UTF-8
43
+ require_paths:
44
+ - lib
45
+ required_ruby_version: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ segments:
50
+ - 0
51
+ version: "0"
52
+ required_rubygems_version: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ segments:
57
+ - 0
58
+ version: "0"
59
+ requirements: []
60
+
61
+ rubyforge_project:
62
+ rubygems_version: 1.3.6
63
+ signing_key:
64
+ specification_version: 3
65
+ summary: US State select Rails plugin
66
+ test_files: []
67
+