ichiban 1.2.3 → 1.2.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/ichiban/nav_helper.rb +27 -33
- data/lib/ichiban/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e75247671503c6905c93fb55cca27be646d68626
|
4
|
+
data.tar.gz: 894a82e6eb0d165d5e6fa58b0517998f0d109a80
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 84d001d474a73ae9cdced63b8f3ecc801dd67f1d65dc866372b7bb15efc82df41371c4848e89e2d86879c8e4b5273f75299166b5f6f9c2a9f741ba6a909ecb7c
|
7
|
+
data.tar.gz: 0057724132944893a1b892193e84b36696c332762396059c441ac882e24c4992d9e627d0bc6775baa78f3d68d74bafbf908154792d5cd75b8e61244b8a37d741
|
data/lib/ichiban/nav_helper.rb
CHANGED
@@ -5,6 +5,7 @@ module Ichiban
|
|
5
5
|
unless items.is_a?(Array)
|
6
6
|
raise "Expected first parameter of NavHelper#nav to be an Array, but got: #{items.inspect}"
|
7
7
|
end
|
8
|
+
options = {sub_paths: :expand}.merge(options)
|
8
9
|
Nav.new(items, options, self).to_html
|
9
10
|
end
|
10
11
|
|
@@ -16,7 +17,7 @@ module Ichiban
|
|
16
17
|
end
|
17
18
|
|
18
19
|
def to_html
|
19
|
-
ul(@items, 0)
|
20
|
+
ul(@items, 0, @options)
|
20
21
|
end
|
21
22
|
|
22
23
|
private
|
@@ -32,26 +33,28 @@ module Ichiban
|
|
32
33
|
@ctx.path_with_slashes(@ctx.current_path).start_with?(@ctx.path_with_slashes(path))
|
33
34
|
end
|
34
35
|
|
35
|
-
# Recursive.
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
36
|
+
# Recursive.
|
37
|
+
def menu_matches_current_path?(path, sub_menu, options)
|
38
|
+
# If the menu item matches the current path exactly, return true.
|
39
|
+
current_path?(path) or
|
40
|
+
|
41
|
+
# If we're allowed to consider sub-paths, and the current path starts with the
|
42
|
+
# menu item's path, return true. E.g. current path /a/b/c/ and menu item path
|
43
|
+
# /a/b/.
|
44
|
+
(options[:sub_paths] != :collapse and current_path_starts_with?(path)) or
|
45
|
+
|
46
|
+
# The path for this menu item did not match. So search recursively for a matching
|
47
|
+
# path in this item's sub-menu.
|
48
|
+
!sub_menu.detect do |item|
|
49
|
+
# If an item has a sub-menu, then that menu must be the third element of the array.
|
50
|
+
# (The format is [text, path, sub_menu, li_options].) So we recursively search the
|
51
|
+
# descendant menu(s) of this item.
|
52
|
+
(item[2].is_a?(Array) and menu_matches_current_path?(item[1], item[2], options))
|
50
53
|
end.nil?
|
51
54
|
end
|
52
55
|
|
53
56
|
# Recursive
|
54
|
-
def ul(items, depth)
|
57
|
+
def ul(items, depth, options)
|
55
58
|
# If we're in the outermost menu, add any passed-in <ul> attributes
|
56
59
|
ul_options = (
|
57
60
|
depth == 0 ?
|
@@ -97,36 +100,27 @@ module Ichiban
|
|
97
100
|
lis << @ctx.content_tag('li', li_attrs) do
|
98
101
|
li_inner_html = ''
|
99
102
|
|
103
|
+
sub_menu_open = (
|
104
|
+
!sub_menu.nil? and
|
105
|
+
menu_matches_current_path?(path, sub_menu, options)
|
106
|
+
)
|
107
|
+
|
100
108
|
# Create the <a> or <span> tag for this item.
|
101
109
|
if current_path?(path)
|
102
110
|
li_inner_html << @ctx.content_tag('span', text, 'class' => 'selected')
|
103
111
|
else
|
104
|
-
if
|
112
|
+
if sub_menu_open
|
105
113
|
a_attrs = {'class' => 'above-selected'}
|
106
114
|
else
|
107
115
|
a_attrs = {}
|
108
116
|
end
|
109
117
|
li_inner_html << @ctx.link_to(text, path, a_attrs)
|
110
118
|
end
|
111
|
-
|
112
|
-
# This item's sub-menu should be open if and only if:
|
113
|
-
#
|
114
|
-
# 1. we are at or inside the item's path; or
|
115
|
-
# 2. we are at or inside a path included in any of this item's descendant menus.
|
116
|
-
|
117
|
-
if sub_menu
|
118
|
-
sub_menu_open = (
|
119
|
-
current_path_starts_with?(path) or
|
120
|
-
menu_matches_current_path?(sub_menu)
|
121
|
-
)
|
122
|
-
else
|
123
|
-
sub_menu_open = false
|
124
|
-
end
|
125
119
|
|
126
120
|
# If the sub-menu is open, then we recursively generate its HTML
|
127
121
|
# and append it to this <li>.
|
128
122
|
if sub_menu_open
|
129
|
-
li_inner_html << ul(sub_menu, depth + 1)
|
123
|
+
li_inner_html << ul(sub_menu, depth + 1, options)
|
130
124
|
end
|
131
125
|
|
132
126
|
li_inner_html
|
data/lib/ichiban/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ichiban
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.2.
|
4
|
+
version: 1.2.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jarrett Colby
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-09-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ejs
|