navbar_highlighter 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +28 -3
- data/lib/navbar_highlighter/helper.rb +3 -2
- data/lib/navbar_highlighter/version.rb +1 -1
- data/navbar_highlighter.gemspec +3 -1
- data/vendor/assets/javascripts/navbar_highlighter.js +19 -4
- metadata +25 -12
- data/.rspec +0 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 91314c4d4c2c928ad9d65908ab7ca568653c9d88
|
4
|
+
data.tar.gz: be88fb072e50d2cc366157ac7b66692a1b8c1a79
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 125abda44364b43824c682c03cdf53bd202b29c4ecc2de33940246760f8518d8eb9e07a9583071a61964aa6cb25f32eb4e9154ada7a7a8cd1d4709f2bf1b3d15
|
7
|
+
data.tar.gz: fb9f40317f0863d78878eba0bc05e6a80056f00ca2071395b4e369995212d58501b5d95b2ae1829c748cf3d3a3805714dcbaf1813f5168e6fdb7584777752344
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Navbar-Highlighter
|
1
|
+
# Navbar-Highlighter
|
2
2
|
|
3
3
|
Navbar highlighter provides an easier way to activate link based on controller and action used by rails.
|
4
4
|
|
@@ -37,16 +37,40 @@ If you are doing so, don't forget to add it to `asset.rb` like so:
|
|
37
37
|
linkHighlighter.init();
|
38
38
|
|
39
39
|
})();
|
40
|
+
Add`<%= navbar_highlighter_tags %>` to any layout that you are using.
|
40
41
|
|
41
|
-
|
42
|
+
---
|
43
|
+
##### Add `data-controller='controller-name'` and `data-action='action-name'` to the links you want to add class based on controller and action.
|
44
|
+
|
45
|
+
---
|
42
46
|
|
43
47
|
#### Add `data-navbar='highlight'` to navbar just like below snippet:
|
44
48
|
|
45
|
-
|
49
|
+
|
50
|
+
<nav data-navbar="highlight">
|
51
|
+
<ul class="primary-nav-list">
|
52
|
+
<li class="primary-menu">
|
53
|
+
<a href="/" class="primary-link" data-controller="sessions" data-action="index">
|
54
|
+
Home
|
55
|
+
</a>
|
56
|
+
</li>
|
57
|
+
|
58
|
+
<li class="primary-menu">
|
59
|
+
<a href="/users" class="primary-link" data-controller="users" data-action="index" data-parent='sessions'>
|
60
|
+
<!-- Adding data-parent='controller_name' will add active-link class to parent link i.e Home link in this case. -->
|
61
|
+
Users
|
62
|
+
</a>
|
63
|
+
</li>
|
64
|
+
<ul>
|
65
|
+
</nav>
|
66
|
+
|
46
67
|
|
47
68
|
**Note:**
|
48
69
|
|
49
70
|
As user hits `sessions_controller` `index` action `Home` link will be active, and when user clicks `Users` link `Users` link will be get `active-link` class.
|
71
|
+
# New feature
|
72
|
+
Adding a `data-parent='controller_name'` to link will add class to parent link as well as the child link.
|
73
|
+
|
50
74
|
## Contributing
|
51
75
|
|
52
76
|
Bug reports and pull requests are welcome on GitHub at https://github.com/abhikanojia/navbar_highlighter. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
@@ -58,3 +82,4 @@ The gem is available as open source under the terms of the [MIT License](https:/
|
|
58
82
|
## Code of Conduct
|
59
83
|
|
60
84
|
Everyone interacting in the NavbarHighlighter project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/abhikanojia/navbar_highlighter/blob/master/CODE_OF_CONDUCT.md).
|
85
|
+
|
@@ -1,8 +1,9 @@
|
|
1
1
|
module Helper
|
2
2
|
def navbar_highlighter_tags
|
3
3
|
''.tap do |str|
|
4
|
-
str.concat("<meta name='controller' content='#{controller_name}'
|
5
|
-
str.concat("
|
4
|
+
str.concat("<meta name='controller' content='#{controller_name}'>")
|
5
|
+
str.concat("\n")
|
6
|
+
str.concat("<meta name='action' content='#{action_name}'>")
|
6
7
|
end.html_safe
|
7
8
|
end
|
8
9
|
end
|
data/navbar_highlighter.gemspec
CHANGED
@@ -21,7 +21,9 @@ Gem::Specification.new do |spec|
|
|
21
21
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
22
22
|
spec.require_paths = ["lib"]
|
23
23
|
|
24
|
+
spec.add_dependency 'jquery-rails', '~> 4.3'
|
25
|
+
spec.add_dependency 'rails', '~> 5.1.4'
|
26
|
+
|
24
27
|
spec.add_development_dependency "bundler", "~> 1.16"
|
25
28
|
spec.add_development_dependency "rake", "~> 10.0"
|
26
|
-
spec.add_development_dependency "rspec", "~> 3.0"
|
27
29
|
end
|
@@ -6,8 +6,12 @@ function NavbarHighlighter(data) {
|
|
6
6
|
this.controllerName = $('meta[name=controller]').attr('content');
|
7
7
|
}
|
8
8
|
|
9
|
-
NavbarHighlighter.prototype.getControllerSelector = function() {
|
10
|
-
|
9
|
+
NavbarHighlighter.prototype.getControllerSelector = function(selector) {
|
10
|
+
if(selector) {
|
11
|
+
return '[data-controller=' + selector + ']';
|
12
|
+
} else {
|
13
|
+
return '[data-controller=' + this.controllerName + ']';
|
14
|
+
}
|
11
15
|
};
|
12
16
|
|
13
17
|
NavbarHighlighter.prototype.getActionSelector = function() {
|
@@ -18,15 +22,26 @@ NavbarHighlighter.prototype.classSelector = function(className) {
|
|
18
22
|
return '.' + className;
|
19
23
|
};
|
20
24
|
|
25
|
+
NavbarHighlighter.prototype.highlightParentIfExist = function(element) {
|
26
|
+
var dataParent = element.data('parent');
|
27
|
+
if(dataParent) {
|
28
|
+
$(this.getControllerSelector(dataParent)).addClass(this.classNameToAdd);
|
29
|
+
}
|
30
|
+
};
|
31
|
+
|
21
32
|
NavbarHighlighter.prototype.init = function() {
|
22
33
|
|
23
34
|
this.navBar.find(
|
24
35
|
this.classSelector(this.linkSelectorClass)
|
25
36
|
).removeClass(this.classNameToAdd);
|
26
37
|
|
27
|
-
this.navBar.find(
|
38
|
+
var element = this.navBar.find(
|
28
39
|
$(this.getControllerSelector() + this.getActionSelector())
|
29
|
-
)
|
40
|
+
);
|
41
|
+
|
42
|
+
element.addClass(this.classNameToAdd);
|
43
|
+
|
44
|
+
this.highlightParentIfExist(element);
|
30
45
|
|
31
46
|
};
|
32
47
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: navbar_highlighter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Abhishek Kanojia
|
@@ -11,47 +11,61 @@ cert_chain: []
|
|
11
11
|
date: 2018-04-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: jquery-rails
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
20
|
-
type: :
|
19
|
+
version: '4.3'
|
20
|
+
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
26
|
+
version: '4.3'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
28
|
+
name: rails
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
33
|
+
version: 5.1.4
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 5.1.4
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.16'
|
34
48
|
type: :development
|
35
49
|
prerelease: false
|
36
50
|
version_requirements: !ruby/object:Gem::Requirement
|
37
51
|
requirements:
|
38
52
|
- - "~>"
|
39
53
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
54
|
+
version: '1.16'
|
41
55
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
56
|
+
name: rake
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|
44
58
|
requirements:
|
45
59
|
- - "~>"
|
46
60
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
61
|
+
version: '10.0'
|
48
62
|
type: :development
|
49
63
|
prerelease: false
|
50
64
|
version_requirements: !ruby/object:Gem::Requirement
|
51
65
|
requirements:
|
52
66
|
- - "~>"
|
53
67
|
- !ruby/object:Gem::Version
|
54
|
-
version: '
|
68
|
+
version: '10.0'
|
55
69
|
description: 'This gem provides an easy way to change navbar links based on controller
|
56
70
|
and action in ruby on rails. Usecase: Can be used to activate certain link based
|
57
71
|
on controller. '
|
@@ -62,7 +76,6 @@ extensions: []
|
|
62
76
|
extra_rdoc_files: []
|
63
77
|
files:
|
64
78
|
- ".gitignore"
|
65
|
-
- ".rspec"
|
66
79
|
- ".travis.yml"
|
67
80
|
- CODE_OF_CONDUCT.md
|
68
81
|
- Gemfile
|
data/.rspec
DELETED