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 +4 -4
- data/README.md +4 -4
- data/lib/nav_helper.rb +8 -4
- data/lib/nav_helper/version.rb +1 -1
- data/spec/helpers/nav_helper_spec.rb +12 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7a972a9e98fc31bc8cfa2813eb3b8080d921d3ac
|
4
|
+
data.tar.gz: 2bd8aa1eddb6c6d4e98328de6588fa191ab5b289
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ecd28eb237ee079c943374262bfdcd928307445ccac54499d2d4e640e6310b11bc1f03c82107498bd42a7e5f2e3559f7b18a0b68ea87875c248247dcb5625d35
|
7
|
+
data.tar.gz: 48a6cfe470cab99ac27c088fb452544029fd2be33d79ebc908faabdcf0d1394608a0975126087af170b1e1c193442cff8bec5d904aa78ea5e81e62dd0b880266
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# NavHelper
|
1
|
+
# NavHelper [](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
|
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
|
|
data/lib/nav_helper.rb
CHANGED
@@ -17,12 +17,16 @@ module NavigationHelper
|
|
17
17
|
path, options = title, path if block_given?
|
18
18
|
|
19
19
|
options ||= {}
|
20
|
-
options.
|
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
|
-
|
23
|
-
|
25
|
+
if current_path?(path, root)
|
26
|
+
wrapper[:class] = [ wrapper[:class], active_class ].compact.join(' ')
|
27
|
+
end
|
24
28
|
|
25
|
-
content_tag(tag,
|
29
|
+
content_tag(tag, wrapper) do
|
26
30
|
if block_given?
|
27
31
|
link_to(path, options, &blk)
|
28
32
|
else
|
data/lib/nav_helper/version.rb
CHANGED
@@ -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.
|
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
|
+
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.
|
108
|
+
rubygems_version: 2.2.2
|
109
109
|
signing_key:
|
110
110
|
specification_version: 4
|
111
111
|
summary: Helper for building nav links.
|