menu_maker 0.0.4 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/menu_maker/menu.rb +43 -18
- data/lib/menu_maker/version.rb +1 -1
- data/test/dummy/log/test.log +3219 -0
- data/test/menu_item_test.rb +83 -0
- data/test/menu_maker_test.rb +3 -3
- data/test/menu_renderer_test.rb +5 -5
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c7e55f905ac5c7999264b81b19e25e94b025ae0a
|
4
|
+
data.tar.gz: 408568b945adf3267293c96fd1db0b7490afee29
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4f174811fd7e5b77870f4eaf005f8919ccd87102a222b245592822e85f018329b1bbbd83c2c24028eb4df8de6162e1becd5ec9463ca6f4c5b5c5e405a1d27ed9
|
7
|
+
data.tar.gz: 333120e0015eb5e48866664a56d9bc0e7146e14509c48cfc4ffcd2ceb87642166039b0fb5b52050fe164dc39dfdb68d38c4053ed7f12f108c955d47de5913643
|
data/lib/menu_maker/menu.rb
CHANGED
@@ -2,10 +2,9 @@ module MenuMaker
|
|
2
2
|
class Menu
|
3
3
|
include Enumerable
|
4
4
|
|
5
|
-
def initialize(renderer
|
6
|
-
@items
|
7
|
-
@
|
8
|
-
@renderer = renderer
|
5
|
+
def initialize(renderer)
|
6
|
+
@items = {}
|
7
|
+
@renderer = renderer
|
9
8
|
|
10
9
|
yield self if block_given?
|
11
10
|
end
|
@@ -28,9 +27,13 @@ module MenuMaker
|
|
28
27
|
end
|
29
28
|
|
30
29
|
def render
|
31
|
-
renderer_for(
|
30
|
+
renderer_for(current_depth).call(self)
|
32
31
|
end
|
33
32
|
|
33
|
+
protected
|
34
|
+
|
35
|
+
attr_writer :current_depth
|
36
|
+
|
34
37
|
private
|
35
38
|
|
36
39
|
def current_item
|
@@ -38,14 +41,14 @@ module MenuMaker
|
|
38
41
|
end
|
39
42
|
|
40
43
|
def current_submenu
|
41
|
-
current_item.submenu ||
|
42
|
-
current_item.create_submenu!(
|
43
|
-
renderer_for(next_depth), next_depth
|
44
|
-
)
|
44
|
+
current_item.submenu || create_submenu!
|
45
45
|
end
|
46
46
|
|
47
|
-
def
|
48
|
-
|
47
|
+
def create_submenu!
|
48
|
+
submenu = Menu.new renderer_for(next_depth)
|
49
|
+
submenu.current_depth = next_depth
|
50
|
+
|
51
|
+
current_item.submenu = submenu
|
49
52
|
end
|
50
53
|
|
51
54
|
def renderer_for(depth)
|
@@ -62,23 +65,41 @@ module MenuMaker
|
|
62
65
|
renderer
|
63
66
|
end
|
64
67
|
|
65
|
-
|
68
|
+
def current_depth
|
69
|
+
@current_depth || 1
|
70
|
+
end
|
71
|
+
|
72
|
+
def next_depth
|
73
|
+
current_depth + 1
|
74
|
+
end
|
75
|
+
|
76
|
+
class MenuItem
|
77
|
+
attr_reader :title, :paths, :options
|
78
|
+
|
79
|
+
def initialize(title, path = nil, options = nil)
|
80
|
+
@title = title
|
81
|
+
@paths = []
|
82
|
+
@options = options
|
83
|
+
|
84
|
+
@paths << path if path
|
85
|
+
end
|
86
|
+
|
66
87
|
attr_accessor :submenu
|
67
88
|
|
68
89
|
def has_submenu?
|
69
90
|
!@submenu.nil?
|
70
91
|
end
|
71
92
|
|
72
|
-
def create_submenu!(renderer, depth)
|
73
|
-
@submenu = Menu.new(renderer, depth)
|
74
|
-
end
|
75
|
-
|
76
93
|
def submenu_paths
|
77
|
-
|
94
|
+
return [] unless has_submenu?
|
95
|
+
|
96
|
+
submenu.items.reduce([]) do |all, item|
|
97
|
+
all + item.paths + item.submenu_paths
|
98
|
+
end.flatten
|
78
99
|
end
|
79
100
|
|
80
101
|
def all_paths
|
81
|
-
[
|
102
|
+
[*paths, *submenu_paths]
|
82
103
|
end
|
83
104
|
|
84
105
|
def has_path?(path)
|
@@ -93,6 +114,10 @@ module MenuMaker
|
|
93
114
|
!!(options && options[method])
|
94
115
|
end
|
95
116
|
|
117
|
+
def path
|
118
|
+
@paths.first
|
119
|
+
end
|
120
|
+
|
96
121
|
def render_submenu
|
97
122
|
has_submenu? ? submenu.render : ''
|
98
123
|
end
|
data/lib/menu_maker/version.rb
CHANGED