link_to_active_state 1.0.0 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,3 @@
1
1
  module LinkToActiveState
2
- VERSION = "1.0.0"
2
+ VERSION = "1.0.2"
3
3
  end
@@ -1,5 +1,6 @@
1
1
  require 'action_view'
2
2
  require 'link_to_active_state'
3
+ require 'pry'
3
4
 
4
5
  module LinkToActiveState
5
6
  module ViewHelpers
@@ -9,6 +10,8 @@ module LinkToActiveState
9
10
  end
10
11
 
11
12
  def link_to_with_active_state(*args, &block)
13
+ options = {}
14
+
12
15
  html_options = if block_given?
13
16
  args.second
14
17
  else
@@ -16,29 +19,29 @@ module LinkToActiveState
16
19
  end
17
20
 
18
21
  if html_options.present? && html_options[:active_on].present?
19
- active_on = html_options[:active_on]
22
+ active_on = html_options.delete(:active_on)
23
+ active_state = html_options.delete(:active_state) || "active"
20
24
 
21
25
  if is_active?(active_on)
22
- active_state = html_options[:active_state] || "active"
23
26
  case active_state
24
27
  when Proc
25
- html_options.merge(active_state.call(html_options))
28
+ options = options.merge(active_state.call(html_options))
26
29
  when String
27
- html_options[:class] = merge_class(html_options[:class], active_state)
30
+ options[:class] = merge_class(html_options[:class], active_state)
28
31
  end
29
32
  end
30
-
31
- html_options.delete(:active_on)
32
- html_options.delete(:active_state)
33
33
  end
34
34
 
35
35
  if html_options.present? && html_options[:active_wrapper]
36
36
  element = html_options.delete(:active_wrapper)
37
+ wrapper_options = html_options.delete(:active_wrapper_options) || {}
38
+ wrapper_options = wrapper_options.merge(options)
37
39
 
38
- content_tag(element, html_options) do
40
+ content_tag(element, wrapper_options) do
39
41
  link_to_without_active_state(*args, &block)
40
42
  end
41
43
  else
44
+ html_options.merge!(options)
42
45
  link_to_without_active_state(*args, &block)
43
46
  end
44
47
  end
@@ -18,5 +18,6 @@ Gem::Specification.new do |gem|
18
18
  gem.require_paths = ["lib"]
19
19
 
20
20
  gem.add_development_dependency "rails", [">= 3.2.11"]
21
- gem.add_development_dependency "rspec", ["~> 2.12.0"]
21
+ gem.add_development_dependency "rspec", ["~> 2.13.0"]
22
+ gem.add_development_dependency "pry", [">= 0.9.12"]
22
23
  end
@@ -75,8 +75,15 @@ describe LinkToActiveState::ViewHelpers::UrlHelper do
75
75
  lt = helper.link_to "Home", "/", :active_on => "/", :active_wrapper => :li
76
76
  lt.should match(/<li>/i)
77
77
  end
78
-
78
+
79
+ it "supports options for the wrapper element" do
80
+ request.stub!(:fullpath).and_return("/wibble")
81
+ li = helper.link_to "Home", "/",
82
+ :active_on => "/",
83
+ :active_wrapper => :li,
84
+ :active_wrapper_options => { :class => "wobble" }
85
+ li.should match(/class=\"wobble\"/i)
86
+ end
79
87
  end
80
-
81
88
  end
82
89
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: link_to_active_state
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-02-17 00:00:00.000000000 Z
12
+ date: 2013-02-25 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -34,7 +34,7 @@ dependencies:
34
34
  requirements:
35
35
  - - ~>
36
36
  - !ruby/object:Gem::Version
37
- version: 2.12.0
37
+ version: 2.13.0
38
38
  type: :development
39
39
  prerelease: false
40
40
  version_requirements: !ruby/object:Gem::Requirement
@@ -42,7 +42,23 @@ dependencies:
42
42
  requirements:
43
43
  - - ~>
44
44
  - !ruby/object:Gem::Version
45
- version: 2.12.0
45
+ version: 2.13.0
46
+ - !ruby/object:Gem::Dependency
47
+ name: pry
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: 0.9.12
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: 0.9.12
46
62
  description: A simple gem to implement active states on links using the standard Rails
47
63
  `link_to` helper.
48
64
  email:
@@ -86,7 +102,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
86
102
  version: '0'
87
103
  requirements: []
88
104
  rubyforge_project:
89
- rubygems_version: 1.8.24
105
+ rubygems_version: 1.8.23
90
106
  signing_key:
91
107
  specification_version: 3
92
108
  summary: Active states for links using the Rails link_to helper.