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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e600823e9f39cd89f4c1b3521a1179806502a061
4
- data.tar.gz: 2ffada4a0eeef512a2985d0142ff35f8bc75fb69
3
+ metadata.gz: 91314c4d4c2c928ad9d65908ab7ca568653c9d88
4
+ data.tar.gz: be88fb072e50d2cc366157ac7b66692a1b8c1a79
5
5
  SHA512:
6
- metadata.gz: 6c88f2bb7a843565f2967ea8ed0405a030a8b4a97c64948a1ed8994aef60b95a9b1b40397d2dc64f16375c53364b066a3c75941917e686a18c02be6ba84f26ba
7
- data.tar.gz: 70b58e14979ff058d17b20d4e2da7f4c2e5c499285654cd869e3ce07c3caf63e86a89be9fd6299df52985e0b04819772abbaf755657e02d201680d9c71c6c5b0
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
- #### Add `data-controller='controller-name'` and `data-action='action-name'` to the links you want to add class based on controller and action.
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
- <script src="https://gist.github.com/abhikanojia/02583e5a383ef77fe5b5125a95421d6c.js"></script>
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("<meta name='action' content='#{action_name}' >")
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
@@ -1,3 +1,3 @@
1
1
  module NavbarHighlighter
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -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
- return '[data-controller=' + this.controllerName + ']';
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
- ).addClass(this.classNameToAdd);
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.1.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: bundler
14
+ name: jquery-rails
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '1.16'
20
- type: :development
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: '1.16'
26
+ version: '4.3'
27
27
  - !ruby/object:Gem::Dependency
28
- name: rake
28
+ name: rails
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '10.0'
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: '10.0'
54
+ version: '1.16'
41
55
  - !ruby/object:Gem::Dependency
42
- name: rspec
56
+ name: rake
43
57
  requirement: !ruby/object:Gem::Requirement
44
58
  requirements:
45
59
  - - "~>"
46
60
  - !ruby/object:Gem::Version
47
- version: '3.0'
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: '3.0'
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
@@ -1,3 +0,0 @@
1
- --format documentation
2
- --color
3
- --require spec_helper