link_to_active_state 0.1.2 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/.public_cert.pem ADDED
@@ -0,0 +1,20 @@
1
+ -----BEGIN CERTIFICATE-----
2
+ MIIDMjCCAhqgAwIBAgIBADANBgkqhkiG9w0BAQUFADA/MREwDwYDVQQDDAhyb2Jv
3
+ dG1heTEVMBMGCgmSJomT8ixkARkWBWdtYWlsMRMwEQYKCZImiZPyLGQBGRYDY29t
4
+ MB4XDTEzMDIwMTEyMjAzOFoXDTE0MDIwMTEyMjAzOFowPzERMA8GA1UEAwwIcm9i
5
+ b3RtYXkxFTATBgoJkiaJk/IsZAEZFgVnbWFpbDETMBEGCgmSJomT8ixkARkWA2Nv
6
+ bTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAN6wix6nt1IBhgSyIeMB
7
+ ytPpn515nwSvJhG1ej7Yt9T0faMCnWTrm8jZtdtXsB/9RwHpUoCqCdttNrm/1jBQ
8
+ j8ddTmqPV9L5W7mvbC4a+4YQ5+xBqG0WV5LDYQek0hXWGM7XJd/eo82CANrgmiu5
9
+ MqCna8ovoABtqXQb+t83DtK0xdL0rSd5zBP752VzKC8/AEw5EZlTWH9xXWy7asF+
10
+ U0nyymwyPKvfwDh02c7WRrz7/8NCCyto7GWfrmD9c4UkIqrsFx40FSkETXapLIpW
11
+ 6q5859c00+weeAImX8gHnCXTxMdcxxmPQ8sZ6KZ/NEyZh7yApJaPVmQI+m2Ou2GA
12
+ JKMCAwEAAaM5MDcwCQYDVR0TBAIwADAdBgNVHQ4EFgQURPXWvYZqwmHnqw4uMjZh
13
+ liL3GgkwCwYDVR0PBAQDAgSwMA0GCSqGSIb3DQEBBQUAA4IBAQCpWF+B6K5megIH
14
+ 9WJxV2Vi81w00CoaxNMQBL38KMUDkq4u4V7EOoYdp9qdQ2tDwJ2CBhIRSPS6bNtp
15
+ GAM1peOCXblsSGoyNWS0kNd8/eWVyMCFt7PsWi4nADVTM7uHYR9MtmIQ5BbsS8OS
16
+ zeufMQfyuV2Yp3a+oGFdGrWa6cicRhvBlJglriUiUGTf/Z45hrNQ1xP9WyPJqTLV
17
+ cEvC1LiLSCSb/v2lFVpA51wdiIC5/CTAgyIMCc7LmToncqgvEY3hQFsLNZlfGtVz
18
+ 5O7cF3CDHuZIFkHlGBg3nC/6n7XV9np8pe9688on4Nb/2zCOwzcwOCM6hJyn8IUf
19
+ zj5dQ3p0
20
+ -----END CERTIFICATE-----
data/README.md CHANGED
@@ -2,7 +2,8 @@
2
2
 
3
3
  [![Build Status](https://travis-ci.org/robotmay/link_to_active_state.png?branch=master)](https://travis-ci.org/robotmay/link_to_active_state) [![Code Climate](https://codeclimate.com/badge.png)](https://codeclimate.com/github/robotmay/link_to_active_state) [![Dependency Status](https://gemnasium.com/robotmay/link_to_active_state.png)](https://gemnasium.com/robotmay/link_to_active_state)
4
4
 
5
- A simple gem to implement active states on links using the standard Rails `link_to` helper.
5
+ A simple gem to implement active states on links using the standard Rails `link_to` helper.
6
+ This can be helpful in navigation lists or buttons to give them a class when the current URL matches a condition on the link helper.
6
7
 
7
8
  ## Installation
8
9
 
@@ -10,7 +11,7 @@ Add this line to your application's Gemfile:
10
11
 
11
12
  gem 'link_to_active_state'
12
13
 
13
- *NOTE*: RubyGems.org is currently in read-only mode, so the gem doesn't yet exist there. Install from the git repo instead:
14
+ Or install from the repository:
14
15
 
15
16
  gem 'link_to_active_state', git: 'git://github.com/robotmay/link_to_active_state.git', tag: 'v0.1.2'
16
17
 
@@ -33,6 +34,11 @@ Test the path using a string/path helper:
33
34
  link_to "Account", account_path, active_on: account_path
34
35
  ```
35
36
 
37
+ Which, if the `request.fullpath` matches `account_path`, will result in:
38
+ ```html
39
+ <a href="/account" class="active">Account</a>
40
+ ```
41
+
36
42
  Using a regular expression:
37
43
  ```ruby
38
44
  link_to "Account", account_path, active_on: /\/account/i
@@ -51,6 +57,10 @@ By default the class "active" will be added to the existing classes of the link.
51
57
  link_to "Account", account_path, active_on: /\/account/i, active_state: "highlighted"
52
58
  ```
53
59
 
60
+ ```html
61
+ <a href="/account" class="highlighted">Account</a>
62
+ ```
63
+
54
64
  You can also customise other options by using a proc:
55
65
  ```ruby
56
66
  link_to "Account", account_path, active_on: /\/account/i, active_state: lambda { |html_options|
@@ -58,6 +68,26 @@ link_to "Account", account_path, active_on: /\/account/i, active_state: lambda {
58
68
  }
59
69
  ```
60
70
 
71
+ ```html
72
+ <a href="/account" data-active="true">Account</a>
73
+ ```
74
+
75
+ ### Wrappers
76
+
77
+ If you need an active class on an li tag, for use in a Bootstrap nav for example:
78
+ ```ruby
79
+ link_to "Account", account_path, active_on: account_path, active_wrapper: :li
80
+ ```
81
+
82
+ Which will result in:
83
+ ```html
84
+ <li class="active">
85
+ <a href="/account" class="active">Account</a>
86
+ </li>
87
+ ```
88
+
89
+ Note the li tag is included as part of the html generated by the link_to helper and should not be added separately.
90
+
61
91
  ## Contributing
62
92
 
63
93
  1. Fork it
@@ -1,3 +1,3 @@
1
1
  module LinkToActiveState
2
- VERSION = "0.1.2"
2
+ VERSION = "1.0.0"
3
3
  end
@@ -14,7 +14,7 @@ module LinkToActiveState
14
14
  else
15
15
  args[2]
16
16
  end
17
-
17
+
18
18
  if html_options.present? && html_options[:active_on].present?
19
19
  active_on = html_options[:active_on]
20
20
 
@@ -32,7 +32,15 @@ module LinkToActiveState
32
32
  html_options.delete(:active_state)
33
33
  end
34
34
 
35
- link_to_without_active_state(*args, &block)
35
+ if html_options.present? && html_options[:active_wrapper]
36
+ element = html_options.delete(:active_wrapper)
37
+
38
+ content_tag(element, html_options) do
39
+ link_to_without_active_state(*args, &block)
40
+ end
41
+ else
42
+ link_to_without_active_state(*args, &block)
43
+ end
36
44
  end
37
45
 
38
46
  private
@@ -43,7 +51,7 @@ module LinkToActiveState
43
51
  when Array
44
52
  active_on.include?(request.fullpath)
45
53
  when Regexp
46
- request.fullpath =~ active_on
54
+ request.fullpath =~ active_on
47
55
  when Proc
48
56
  active_on.arity == 1 ? active_on.call(request) : active_on.call
49
57
  end
@@ -17,9 +17,6 @@ Gem::Specification.new do |gem|
17
17
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
18
  gem.require_paths = ["lib"]
19
19
 
20
- gem.cert_chain = ["gem-public_cert.pem"]
21
- gem.signing_key = ENV['PRIVATE_KEY']
22
-
23
20
  gem.add_development_dependency "rails", [">= 3.2.11"]
24
21
  gem.add_development_dependency "rspec", ["~> 2.12.0"]
25
22
  end
@@ -34,7 +34,7 @@ describe LinkToActiveState::ViewHelpers::UrlHelper do
34
34
  def fullpath
35
35
  end
36
36
  end
37
-
37
+
38
38
  Request.new
39
39
  end
40
40
 
@@ -42,16 +42,41 @@ describe LinkToActiveState::ViewHelpers::UrlHelper do
42
42
  helper.stub!(:request).and_return(request)
43
43
  end
44
44
 
45
- it "adds an active state when the current request path matches" do
46
- request.stub!(:fullpath).and_return("/")
47
- lt = helper.link_to "Home", "/", :active_on => "/"
48
- lt.should match(/class=\"active\"/i)
45
+ context "when the current request path matches" do
46
+
47
+ it "adds an active state" do
48
+ request.stub!(:fullpath).and_return("/")
49
+ lt = helper.link_to "Home", "/", :active_on => "/"
50
+ lt.should match(/class=\"active\"/i)
51
+ end
52
+
53
+ it "encloses link in an element with active state if active_wrapper is true" do
54
+ request.stub!(:fullpath).and_return("/")
55
+ lt = helper.link_to "Home", "/", :active_on => "/", :active_wrapper => :li
56
+ lt.should match(/li class=\"active\"/i)
57
+ end
58
+
59
+ it "doesn't enclose link in an element if active_wrapper is not specified" do
60
+ request.stub!(:fullpath).and_return("/")
61
+ lt = helper.link_to "Home", "/", :active_on => "/"
62
+ lt.should_not match(/li class=\"active\"/i)
63
+ end
49
64
  end
50
65
 
51
- it "doesn't add an active state when the current request doesn't match" do
52
- request.stub!(:fullpath).and_return("/wibble")
53
- lt = helper.link_to "Madness", "/wobble", :active_on => "/wobble"
54
- lt.should_not match(/class=\"active\"/i)
66
+ context "when the current request doesn't match" do
67
+ it "doesn't add an active state" do
68
+ request.stub!(:fullpath).and_return("/wibble")
69
+ lt = helper.link_to "Madness", "/wobble", :active_on => "/wobble"
70
+ lt.should_not match(/class=\"active\"/i)
71
+ end
72
+
73
+ it "encloses link in an element if active_wrapper is true" do
74
+ request.stub!(:fullpath).and_return("/wibble")
75
+ lt = helper.link_to "Home", "/", :active_on => "/", :active_wrapper => :li
76
+ lt.should match(/<li>/i)
77
+ end
78
+
55
79
  end
80
+
56
81
  end
57
82
  end
metadata CHANGED
@@ -1,42 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: link_to_active_state
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 1.0.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
8
8
  - Robert May
9
9
  autorequire:
10
10
  bindir: bin
11
- cert_chain:
12
- - !binary |-
13
- LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSURNakNDQWhxZ0F3SUJB
14
- Z0lCQURBTkJna3Foa2lHOXcwQkFRVUZBREEvTVJFd0R3WURWUVFEREFoeWIy
15
- SnYKZEcxaGVURVZNQk1HQ2dtU0pvbVQ4aXhrQVJrV0JXZHRZV2xzTVJNd0VR
16
- WUtDWkltaVpQeUxHUUJHUllEWTI5dApNQjRYRFRFek1ESXdNVEV5TWpBek9G
17
- b1hEVEUwTURJd01URXlNakF6T0Zvd1B6RVJNQThHQTFVRUF3d0ljbTlpCmIz
18
- UnRZWGt4RlRBVEJnb0praWFKay9Jc1pBRVpGZ1ZuYldGcGJERVRNQkVHQ2dt
19
- U0pvbVQ4aXhrQVJrV0EyTnYKYlRDQ0FTSXdEUVlKS29aSWh2Y05BUUVCQlFB
20
- RGdnRVBBRENDQVFvQ2dnRUJBTjZ3aXg2bnQxSUJoZ1N5SWVNQgp5dFBwbjUx
21
- NW53U3ZKaEcxZWo3WXQ5VDBmYU1DbldUcm04alp0ZHRYc0IvOVJ3SHBVb0Nx
22
- Q2R0dE5ybS8xakJRCmo4ZGRUbXFQVjlMN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LS0tCg==
39
- date: 2013-02-01 00:00:00.000000000 Z
11
+ cert_chain: []
12
+ date: 2013-02-17 00:00:00.000000000 Z
40
13
  dependencies:
41
14
  - !ruby/object:Gem::Dependency
42
15
  name: rails
@@ -79,6 +52,7 @@ extensions: []
79
52
  extra_rdoc_files: []
80
53
  files:
81
54
  - .gitignore
55
+ - .public_cert.pem
82
56
  - .travis.yml
83
57
  - Gemfile
84
58
  - LICENSE.txt
@@ -112,7 +86,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
112
86
  version: '0'
113
87
  requirements: []
114
88
  rubyforge_project:
115
- rubygems_version: 1.8.23
89
+ rubygems_version: 1.8.24
116
90
  signing_key:
117
91
  specification_version: 3
118
92
  summary: Active states for links using the Rails link_to helper.
data.tar.gz.sig DELETED
Binary file
metadata.gz.sig DELETED
Binary file