nav_helper 0.1.0 → 0.2.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: dc636af0eafe2786f497ffe73111698409368252
4
- data.tar.gz: c2b2f38b70c8272a6a7aaed53a9154b77b53528f
3
+ metadata.gz: 7a972a9e98fc31bc8cfa2813eb3b8080d921d3ac
4
+ data.tar.gz: 2bd8aa1eddb6c6d4e98328de6588fa191ab5b289
5
5
  SHA512:
6
- metadata.gz: d6d761b6b78fbcc96dd89109be5058382abc406e7a1a8443919dc26e181b2855e0d8439bb90e437ca2831c064a6c6aa15d68a38e6c906e03bc98b242ae260694
7
- data.tar.gz: 00d08c1bf7eafb3772fc64d9e17fee3a6cb5830de5d73b86e00a46bcb519a552027690a4d4c4aebe787291858f84c6f556e9b927fb2dff4209c3c8605b329ae1
6
+ metadata.gz: ecd28eb237ee079c943374262bfdcd928307445ccac54499d2d4e640e6310b11bc1f03c82107498bd42a7e5f2e3559f7b18a0b68ea87875c248247dcb5625d35
7
+ data.tar.gz: 48a6cfe470cab99ac27c088fb452544029fd2be33d79ebc908faabdcf0d1394608a0975126087af170b1e1c193442cff8bec5d904aa78ea5e81e62dd0b880266
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # NavHelper
1
+ # NavHelper [![Build Status](https://travis-ci.org/VortexGrenade/nav_helper.svg?branch=v0.1.0)](https://travis-ci.org/VortexGrenade/nav_helper)
2
2
 
3
3
  Helper for building nav links.
4
4
 
@@ -11,11 +11,11 @@ By default, helper generates link, wrapped with `<li>` and sets class "active",
11
11
  </ul>
12
12
  ```
13
13
 
14
- Also, you can customize wrapper tag and navigation root path:
14
+ Also, you can customize wrapper, active class and navigation root path:
15
15
  ```html
16
16
  <div class="nav">
17
- <%= nav_item('Posts', admin_posts_path, tag: :div, root: admin_path) %>
18
- <%= nav_item('Users', admin_users_path, tag: :div, root: admin_path) %>
17
+ <%= nav_item('Posts', admin_posts_path, active_class: 'activated' wrapper:{tag: :div, class: list-item}, root: admin_path) %>
18
+ <%= nav_item('Users', admin_users_path, active_class: 'activated' wrapper:{tag: :div, class: list-item}, root: admin_path) %>
19
19
  </div>
20
20
  ```
21
21
 
@@ -17,12 +17,16 @@ module NavigationHelper
17
17
  path, options = title, path if block_given?
18
18
 
19
19
  options ||= {}
20
- options.reverse_merge!(tag: :li, root: nil)
20
+ root = options.delete(:root)
21
+ active_class = options.delete(:active_class) || 'active'
22
+ wrapper = options.delete(:wrapper) || {}
23
+ tag = wrapper.delete(:tag) || :li
21
24
 
22
- tag = options.delete(:tag)
23
- is_active = current_path?(path, options.delete(:root))
25
+ if current_path?(path, root)
26
+ wrapper[:class] = [ wrapper[:class], active_class ].compact.join(' ')
27
+ end
24
28
 
25
- content_tag(tag, class: (:active if is_active)) do
29
+ content_tag(tag, wrapper) do
26
30
  if block_given?
27
31
  link_to(path, options, &blk)
28
32
  else
@@ -1,3 +1,3 @@
1
1
  module NavHelper
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -41,6 +41,18 @@ describe NavigationHelper, type: [:helper] do
41
41
  expect(helper.nav_item('Bar', '/admin', root: '/admin')).to eq(%{<li><a href="/admin">Bar</a></li>})
42
42
  end
43
43
 
44
+ it 'allows custom active class' do
45
+ helper.request.path = '/admin/foo/bar'
46
+
47
+ expect(helper.nav_item('Foo', '/admin/foo/bar', root: '/admin', active_class: 'bro')).to eq(%{<li class="bro"><a href="/admin/foo/bar">Foo</a></li>})
48
+ end
49
+
50
+ it 'allows custom wrapper' do
51
+ helper.request.path = '/admin/foo/bar'
52
+
53
+ expect(helper.nav_item('Foo', '/admin/fo', root: '/admin', wrapper: {tag: :div, class: 'bro'})).to eq(%{<div class="bro"><a href="/admin/fo">Foo</a></div>})
54
+ end
55
+
44
56
  it 'generates nav item with block' do
45
57
  expect(helper.nav_item('/fo') do
46
58
  'FOO'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nav_helper
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
  - Okhlopkov Anatoly
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-11-10 00:00:00.000000000 Z
11
+ date: 2014-12-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -105,7 +105,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
105
105
  version: '0'
106
106
  requirements: []
107
107
  rubyforge_project:
108
- rubygems_version: 2.4.2
108
+ rubygems_version: 2.2.2
109
109
  signing_key:
110
110
  specification_version: 4
111
111
  summary: Helper for building nav links.