us_states_select 1.0.0 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md ADDED
@@ -0,0 +1,47 @@
1
+ us-state-select-plugin
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
+ ## Changing Option/Value with :show
13
+
14
+ The default...
15
+
16
+ <%= us_state_select 'child', 'state'%>
17
+
18
+ ...will yield this:
19
+
20
+ <option value="AK">Alaska</option>
21
+
22
+ - - -
23
+
24
+ Or you can change it up...
25
+
26
+ <%= us_state_select 'child', 'state', :show => :full %>
27
+
28
+ ...and get this.
29
+
30
+ <option value="Alaska">Alaska</option>
31
+
32
+ - - -
33
+
34
+ Options are:
35
+
36
+ * :full = <option value="Alaska">Alaska</option>
37
+ * :full_abb = <option value="AK">Alaska</option>
38
+ * :abbreviations = <option value="AK">AK</option>
39
+ * :abb_full_abb = <option value="AK">AK - Alaska</option>
40
+
41
+ You can also pass a proc to show:
42
+
43
+ <%= us_state_select 'child', 'state', :show => Proc.new {|state| [state.first, state.first]} %>
44
+
45
+ The array you are iterating over looks like this:
46
+
47
+ [["Alaska", "AK"], ["Alabama","AL"], ...]
data/Rakefile CHANGED
@@ -9,7 +9,12 @@ begin
9
9
  s.summary = %Q{US State select Rails plugin}
10
10
  s.homepage = "http://github.com/thincloud/us-state-select-plugin"
11
11
  s.description = "US State select Rails plugin"
12
- s.authors = ["Larry Sprock"]
12
+ s.authors = ["Rick Olson","Larry Sprock"]
13
+
14
+ s.add_runtime_dependency "rails", '>= 1.2'
15
+
16
+ s.files.exclude 'init.rb'
17
+ s.files.exclude 'us_states_select.gemspec'
13
18
  end
14
19
  rescue LoadError
15
20
  puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.0.0
1
+ 1.2.0
@@ -1,38 +1,33 @@
1
1
  module ActionView
2
2
  module Helpers
3
3
  module FormOptionsHelper
4
- def us_state_options_for_select(selected = nil, us_state_options = {})
4
+ def us_state_options_for_select(selected = nil, options = {})
5
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]
6
+ priority_states = lambda { |state| options[:priority].include?(state.last) }
7
+ options[:show] = :full if options[:with_abbreviation]
8
+ states_label = case options[:show]
9
9
  when :full_abb then lambda { |state| [state.first, state.last] }
10
10
  when :full then lambda { |state| [state.first, state.first] }
11
11
  when :abbreviations then lambda { |state| [state.last, state.last] }
12
12
  when :abb_full_abb then lambda { |state| ["#{state.last} - #{state.first}", state.last] }
13
13
  else lambda { |state| state }
14
14
  end
15
+ states_label = options[:show] if options[:show].is_a?(Proc)
15
16
 
16
- if us_state_options[:include_blank]
17
- state_options += "<option value=\"\">--</option>\n"
18
- end
19
-
20
- if us_state_options[:priority]
17
+ if options[:priority]
21
18
  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)
19
+ state_options += "<option value=\"\" disabled=\"disabled\">-------------</option>\n"
20
+
21
+ selected = nil if options[:priority].include?(selected)
29
22
  end
30
23
 
31
- return state_options
24
+ state_options += options_for_select(US_STATES.collect(&states_label), selected)
25
+ state_options
32
26
  end
33
27
 
34
28
  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)
29
+ options.merge!(us_state_options)
30
+ InstanceTag.new(object, method, self, options.delete(:object)).to_us_state_select_tag(options, html_options)
36
31
  end
37
32
 
38
33
  private
@@ -51,21 +46,10 @@ module ActionView
51
46
  end
52
47
 
53
48
  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)
49
+ def to_us_state_select_tag(options, html_options)
66
50
  html_options = html_options.stringify_keys
67
51
  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)
52
+ content_tag("select", add_options(us_state_options_for_select(value(object), options), options, value(object)), html_options)
69
53
  end
70
54
  end
71
55
 
metadata CHANGED
@@ -1,67 +1,61 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
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
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.2.0
5
+ prerelease:
10
6
  platform: ruby
11
- authors:
7
+ authors:
8
+ - Rick Olson
12
9
  - Larry Sprock
13
10
  autorequire:
14
11
  bindir: bin
15
12
  cert_chain: []
16
-
17
- date: 2010-03-23 00:00:00 -04:00
18
- default_executable:
19
- dependencies: []
20
-
13
+ date: 2012-01-10 00:00:00.000000000Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: rails
17
+ requirement: &2157464820 !ruby/object:Gem::Requirement
18
+ none: false
19
+ requirements:
20
+ - - ! '>='
21
+ - !ruby/object:Gem::Version
22
+ version: '1.2'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: *2157464820
21
26
  description: US State select Rails plugin
22
27
  email:
23
28
  executables: []
24
-
25
29
  extensions: []
26
-
27
- extra_rdoc_files:
28
- - README
29
- files:
30
- - README
30
+ extra_rdoc_files:
31
+ - README.md
32
+ files:
33
+ - README.md
31
34
  - Rakefile
32
35
  - VERSION
33
- - init.rb
34
36
  - lib/us_states_select.rb
35
- - us_states_select.gemspec
36
- has_rdoc: true
37
37
  homepage: http://github.com/thincloud/us-state-select-plugin
38
38
  licenses: []
39
-
40
39
  post_install_message:
41
- rdoc_options:
42
- - --charset=UTF-8
43
- require_paths:
40
+ rdoc_options: []
41
+ require_paths:
44
42
  - 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"
43
+ required_ruby_version: !ruby/object:Gem::Requirement
44
+ none: false
45
+ requirements:
46
+ - - ! '>='
47
+ - !ruby/object:Gem::Version
48
+ version: '0'
49
+ required_rubygems_version: !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
59
55
  requirements: []
60
-
61
56
  rubyforge_project:
62
- rubygems_version: 1.3.6
57
+ rubygems_version: 1.8.10
63
58
  signing_key:
64
59
  specification_version: 3
65
60
  summary: US State select Rails plugin
66
61
  test_files: []
67
-
data/README DELETED
@@ -1,32 +0,0 @@
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/init.rb DELETED
@@ -1 +0,0 @@
1
- require 'us_states_select'
@@ -1,41 +0,0 @@
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
-