link_to_active_state 1.0.7 → 1.0.8

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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 29ddfa2d41bf42590f15f13cd9855ad7d0975461
4
+ data.tar.gz: 64ffecdfbe4acd7be542c9deb3631fc807eb2542
5
+ SHA512:
6
+ metadata.gz: 643104f46becb061bacf9b052f7dcd6c0fe0421ae1140f4cd04987f15ae6326690a9c39ba76ae1173ec81e26e7a8f83e6bddff0682a0306fb4944436d25bf9ee
7
+ data.tar.gz: 3937bced3f91d5ef03ba0b8c855575e642d77ed4714b4fba5d7ecc0b0336286a45fb39b922d436b0dd9f6f100e58189d9c7c3724a342defbb9c8a2f92b0b1e2f
data/.travis.yml CHANGED
@@ -1,11 +1,9 @@
1
1
  language: ruby
2
2
  rvm:
3
+ - 2.0.0
3
4
  - 1.9.3
4
5
  - 1.9.2
5
- - jruby-18mode
6
6
  - jruby-19mode
7
- - rbx-18mode
8
7
  - rbx-19mode
9
8
  - ruby-head
10
9
  - jruby-head
11
- - 1.8.7
data/README.md CHANGED
@@ -13,7 +13,7 @@ Add this line to your application's Gemfile:
13
13
 
14
14
  Or install from the repository:
15
15
 
16
- gem 'link_to_active_state', git: 'git://github.com/robotmay/link_to_active_state.git', tag: 'v0.1.2'
16
+ gem 'link_to_active_state', git: 'git://github.com/robotmay/link_to_active_state.git', tag: 'v1.0.5'
17
17
 
18
18
  And then execute:
19
19
 
@@ -1,3 +1,3 @@
1
1
  module LinkToActiveState
2
- VERSION = "1.0.7"
2
+ VERSION = "1.0.8"
3
3
  end
@@ -9,14 +9,13 @@ module LinkToActiveState
9
9
  end
10
10
 
11
11
  def link_to_with_active_state(*args, &block)
12
- options = {}
13
-
14
12
  link_options, html_options = if block_given?
15
13
  [args.first, args.second]
16
14
  else
17
15
  [args[1], args[2]]
18
16
  end
19
17
 
18
+ options = {}
20
19
  link_options ||= {}
21
20
  html_options ||= {}
22
21
  wrapper_options = html_options.delete(:active_wrapper_options) || {}
@@ -25,23 +24,20 @@ module LinkToActiveState
25
24
  active_on = html_options.delete(:active_on)
26
25
  active_state = html_options.delete(:active_state) || "active"
27
26
 
28
- if is_active?(active_on, link_options)
27
+ if is_active?(active_on, link_options, html_options)
29
28
  case active_state
30
29
  when Proc
31
30
  options = options.merge(active_state.call(html_options))
31
+ wrapper_options = wrapper_options.merge(active_state.call(html_options))
32
32
  when String
33
33
  options[:class] = merge_class(html_options[:class], active_state)
34
+ wrapper_options[:class] = merge_class(wrapper_options[:class], active_state)
34
35
  end
35
36
  end
36
37
  end
37
38
 
38
39
  if html_options.present? && html_options[:active_wrapper]
39
- if wrapper_options[:class].present?
40
- options[:class] = merge_class(wrapper_options[:class], options[:class])
41
- end
42
-
43
40
  element_or_proc = html_options.delete(:active_wrapper)
44
- wrapper_options.merge!(options)
45
41
 
46
42
  render_with_wrapper(element_or_proc, wrapper_options) do
47
43
  link_to_without_active_state(*args, &block)
@@ -53,20 +49,26 @@ module LinkToActiveState
53
49
  end
54
50
 
55
51
  private
56
- def is_active?(active_on, link_options = {})
52
+ def is_active?(active_on, link_options = {}, html_options = {})
53
+ if html_options.present? && html_options[:ignore_query]
54
+ path = request.fullpath.gsub( /\?.*/, "" )
55
+ else
56
+ path = request.fullpath
57
+ end
58
+
57
59
  case active_on
58
60
  when String
59
- request.fullpath == active_on
61
+ path == active_on
60
62
  when Array
61
- active_on.include?(request.fullpath)
63
+ active_on.include?(path)
62
64
  when Regexp
63
- request.fullpath =~ active_on
65
+ path =~ active_on
64
66
  when Proc
65
67
  active_on.arity == 1 ? active_on.call(request) : active_on.call
66
68
  else
67
- # Anything else we'll take as a true argument, and match the link's URL
69
+ # Anything else we'll take as a true argument, and match the link's URL (including any query string)
68
70
  url = url_for(link_options)
69
- request.fullpath == url
71
+ path == url
70
72
  end
71
73
  end
72
74
 
@@ -74,7 +76,7 @@ module LinkToActiveState
74
76
  original ||= ""
75
77
  [original, new].delete_if(&:blank?).join(" ")
76
78
  end
77
-
79
+
78
80
  def render_with_wrapper(element_or_proc, wrapper_options, &block)
79
81
  content = block.call
80
82
 
@@ -10,6 +10,19 @@ end
10
10
  describe LinkToActiveState::ViewHelpers::UrlHelper do
11
11
  let(:helper) { App::Helper.new }
12
12
 
13
+ let(:request) do
14
+ class Request
15
+ def fullpath
16
+ end
17
+ end
18
+
19
+ Request.new
20
+ end
21
+
22
+ before(:each) do
23
+ helper.stub!(:request).and_return(request)
24
+ end
25
+
13
26
  context "integration with ActionView" do
14
27
  it "aliases the original link_to helper" do
15
28
  helper.should respond_to(:link_to_without_active_state)
@@ -29,19 +42,6 @@ describe LinkToActiveState::ViewHelpers::UrlHelper do
29
42
  end
30
43
 
31
44
  context "active states on links" do
32
- let(:request) do
33
- class Request
34
- def fullpath
35
- end
36
- end
37
-
38
- Request.new
39
- end
40
-
41
- before(:each) do
42
- helper.stub!(:request).and_return(request)
43
- end
44
-
45
45
  context "when the current request path matches" do
46
46
  it "adds an active state" do
47
47
  request.stub!(:fullpath).and_return("/")
@@ -66,6 +66,18 @@ describe LinkToActiveState::ViewHelpers::UrlHelper do
66
66
  lt = helper.link_to "Home", "/", :active_on => "/"
67
67
  lt.should_not match(/li class=\"active\"/i)
68
68
  end
69
+
70
+ it "matches in spite of query string if ignore query is true" do
71
+ request.stub!(:fullpath).and_return("/wobble?test=true")
72
+ lt = helper.link_to "Madness", "/wobble", :active_on => true, :ignore_query => true
73
+ lt.should match(/class=\"active\"/i)
74
+ end
75
+
76
+ it "doesn't match in spite of query string if ignore query is not specified" do
77
+ request.stub!(:fullpath).and_return("/wobble?test=true")
78
+ lt = helper.link_to "Madness", "/wobble", :active_on => true
79
+ lt.should_not match(/class=\"active\"/i)
80
+ end
69
81
  end
70
82
 
71
83
  context "when the current request doesn't match" do
@@ -82,29 +94,32 @@ describe LinkToActiveState::ViewHelpers::UrlHelper do
82
94
  end
83
95
  end
84
96
 
85
- describe "wrapper element support" do
97
+ describe "wrapper element" do
86
98
  it "supports options for the wrapper element" do
87
- li = helper.link_to "Home", "/",
99
+ li = helper.link_to "Home", "/",
100
+ :class => "wobble",
88
101
  :active_on => "/",
89
102
  :active_wrapper => :li,
90
- :active_wrapper_options => { :class => "wobble" }
91
- li.should match(/class=\"wobble\"/i)
103
+ :active_wrapper_options => { :class => "wibble" }
104
+ li.should match(/class=\"wibble\"/i)
92
105
  end
93
106
 
94
107
  it "supports a proc as the wrapper element" do
95
108
  request.stub!(:fullpath).and_return("/")
96
109
  li = helper.link_to "Home", "/",
110
+ :class => "wobble",
97
111
  :active_on => "/",
98
112
  :active_wrapper => proc { |link, wrapper_options|
99
113
  "<li class=\"#{wrapper_options[:class]}\">#{link}</li>"
100
114
  }
101
115
  li.should match(/<li class=\"active\">/i)
102
- li.should match(/<a href/i)
116
+ li.should match(/<a class=\"wobble\" href/i)
103
117
  end
104
-
118
+
105
119
  it "supports options on proc wrapper elements" do
106
120
  request.stub!(:fullpath).and_return("/")
107
121
  li = helper.link_to "Home", "/",
122
+ :class => "wobble",
108
123
  :active_on => "/",
109
124
  :active_wrapper_options => { :class => "wibble" },
110
125
  :active_wrapper => proc { |link, wrapper_options|
metadata CHANGED
@@ -1,46 +1,41 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: link_to_active_state
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.7
5
- prerelease:
4
+ version: 1.0.8
6
5
  platform: ruby
7
6
  authors:
8
7
  - Robert May
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-02-25 00:00:00.000000000 Z
11
+ date: 2015-09-10 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: rails
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - ! '>='
17
+ - - ">="
20
18
  - !ruby/object:Gem::Version
21
19
  version: 3.2.11
22
20
  type: :development
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
- - - ! '>='
24
+ - - ">="
28
25
  - !ruby/object:Gem::Version
29
26
  version: 3.2.11
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: rspec
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
- - - ~>
31
+ - - "~>"
36
32
  - !ruby/object:Gem::Version
37
33
  version: 2.13.0
38
34
  type: :development
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
- - - ~>
38
+ - - "~>"
44
39
  - !ruby/object:Gem::Version
45
40
  version: 2.13.0
46
41
  description: A simple gem to implement active states on links using the standard Rails
@@ -51,9 +46,9 @@ executables: []
51
46
  extensions: []
52
47
  extra_rdoc_files: []
53
48
  files:
54
- - .gitignore
55
- - .public_cert.pem
56
- - .travis.yml
49
+ - ".gitignore"
50
+ - ".public_cert.pem"
51
+ - ".travis.yml"
57
52
  - Gemfile
58
53
  - LICENSE.txt
59
54
  - README.md
@@ -68,27 +63,26 @@ files:
68
63
  - spec/spec_helper.rb
69
64
  homepage: ''
70
65
  licenses: []
66
+ metadata: {}
71
67
  post_install_message:
72
68
  rdoc_options: []
73
69
  require_paths:
74
70
  - lib
75
71
  required_ruby_version: !ruby/object:Gem::Requirement
76
- none: false
77
72
  requirements:
78
- - - ! '>='
73
+ - - ">="
79
74
  - !ruby/object:Gem::Version
80
75
  version: '0'
81
76
  required_rubygems_version: !ruby/object:Gem::Requirement
82
- none: false
83
77
  requirements:
84
- - - ! '>='
78
+ - - ">="
85
79
  - !ruby/object:Gem::Version
86
80
  version: '0'
87
81
  requirements: []
88
82
  rubyforge_project:
89
- rubygems_version: 1.8.23
83
+ rubygems_version: 2.4.5.1
90
84
  signing_key:
91
- specification_version: 3
85
+ specification_version: 4
92
86
  summary: Active states for links using the Rails link_to helper.
93
87
  test_files:
94
88
  - spec/link_to_active_state/view_helpers_spec.rb