menu_maker 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 +4 -4
- data/lib/menu_maker/custom_submenu_renderer.rb +1 -1
- data/lib/menu_maker/menu.rb +11 -9
- data/lib/menu_maker/menu_renderer.rb +4 -5
- data/lib/menu_maker/path.rb +61 -0
- data/lib/menu_maker/version.rb +1 -1
- data/lib/menu_maker.rb +1 -0
- data/test/dummy/log/test.log +13707 -0
- data/test/menu_item_test.rb +26 -2
- data/test/menu_renderer_test.rb +15 -0
- data/test/path_test.rb +84 -0
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 554575bd90faff34a0416ecee38bdf5a8e7bf58b
|
4
|
+
data.tar.gz: 627a276776b88a6d9c252fe0b2825853a66731b6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a46e7476f38bb66ad43d3f9385fa97769bcb25265fb631e21618bc4a030caba6e21f05e78c50f7f6b4996d2db39603b3a9b79c6c05845781df45f60b7383cfce
|
7
|
+
data.tar.gz: 6dc30576b1cd50ca7c6c05dbe944399705ba94da80b705f0ee783f6a4de3b70f93575dadfda373e57c0c92d34442479edb61720c1435c4ef20b9e9609c0e6fc8
|
@@ -2,7 +2,7 @@ module MenuMaker
|
|
2
2
|
class CustomSubmenuRenderer < MenuRenderer
|
3
3
|
render do
|
4
4
|
output = build_menu do |item|
|
5
|
-
options = { link: { class: 'active' } } if item.
|
5
|
+
options = { link: { class: 'active' } } if item.has_path? current_path
|
6
6
|
h.li(item.title, item.path, options || {})
|
7
7
|
end
|
8
8
|
|
data/lib/menu_maker/menu.rb
CHANGED
@@ -17,8 +17,8 @@ module MenuMaker
|
|
17
17
|
items.each(&block)
|
18
18
|
end
|
19
19
|
|
20
|
-
def add(title,
|
21
|
-
@items[title] = MenuItem.new(title,
|
20
|
+
def add(title, *paths, **options)
|
21
|
+
@items[title] = MenuItem.new(title, *paths, options)
|
22
22
|
@current_item = title
|
23
23
|
|
24
24
|
yield current_submenu if block_given?
|
@@ -74,14 +74,12 @@ module MenuMaker
|
|
74
74
|
end
|
75
75
|
|
76
76
|
class MenuItem
|
77
|
-
attr_reader :title, :
|
77
|
+
attr_reader :title, :options
|
78
78
|
|
79
|
-
def initialize(title,
|
79
|
+
def initialize(title, *paths, **options)
|
80
80
|
@title = title
|
81
|
-
@paths =
|
81
|
+
@paths = paths.map { |p| Path.convert(p) }
|
82
82
|
@options = options
|
83
|
-
|
84
|
-
@paths << path if path
|
85
83
|
end
|
86
84
|
|
87
85
|
attr_accessor :submenu
|
@@ -90,6 +88,10 @@ module MenuMaker
|
|
90
88
|
!@submenu.nil?
|
91
89
|
end
|
92
90
|
|
91
|
+
def paths
|
92
|
+
@paths
|
93
|
+
end
|
94
|
+
|
93
95
|
def submenu_paths
|
94
96
|
return [] unless has_submenu?
|
95
97
|
|
@@ -103,7 +105,7 @@ module MenuMaker
|
|
103
105
|
end
|
104
106
|
|
105
107
|
def has_path?(path)
|
106
|
-
all_paths.
|
108
|
+
all_paths.include? Path.convert(path)
|
107
109
|
end
|
108
110
|
|
109
111
|
def method_missing(method, *args)
|
@@ -115,7 +117,7 @@ module MenuMaker
|
|
115
117
|
end
|
116
118
|
|
117
119
|
def path
|
118
|
-
@paths.first
|
120
|
+
@paths.first.address
|
119
121
|
end
|
120
122
|
|
121
123
|
def render_submenu
|
@@ -44,16 +44,15 @@ module MenuMaker
|
|
44
44
|
private
|
45
45
|
|
46
46
|
def find_current_path(current_path)
|
47
|
-
current_path ||
|
47
|
+
Path.convert(current_path || request || '')
|
48
48
|
end
|
49
49
|
|
50
50
|
def helpers_has_request?
|
51
|
-
helpers.respond_to?(:request)
|
52
|
-
helpers.request.respond_to?(:path)
|
51
|
+
helpers.respond_to?(:request)
|
53
52
|
end
|
54
53
|
|
55
|
-
def
|
56
|
-
helpers.request
|
54
|
+
def request
|
55
|
+
helpers.request if helpers_has_request?
|
57
56
|
end
|
58
57
|
end
|
59
58
|
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
module MenuMaker
|
2
|
+
class Path
|
3
|
+
METHODS = %i[get post put patch delete]
|
4
|
+
|
5
|
+
attr_reader :method, :address
|
6
|
+
|
7
|
+
def self.convert(path)
|
8
|
+
method = path.class.name.to_s.split('::').last.to_s.downcase
|
9
|
+
method = :other unless Path.respond_to? "from_#{method}"
|
10
|
+
|
11
|
+
Path.send "from_#{method}", path
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.from_string(address)
|
15
|
+
Path.new(:get, address.to_s)
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.from_array(path)
|
19
|
+
has_method = proc { |el| METHODS.include? el }
|
20
|
+
|
21
|
+
method = path.find(&has_method) || :get
|
22
|
+
address = path.delete_if(&has_method).first
|
23
|
+
|
24
|
+
new method, address
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.from_other(object)
|
28
|
+
fail PathError unless %i[path method].all? { |m| object.respond_to?(m) }
|
29
|
+
|
30
|
+
new(object.method.to_sym.downcase, object.path)
|
31
|
+
end
|
32
|
+
|
33
|
+
def self.from_path(path)
|
34
|
+
path if path.is_a?(Path) or fail PathError
|
35
|
+
end
|
36
|
+
|
37
|
+
def initialize(method, address)
|
38
|
+
fail PathError unless METHODS.include? method
|
39
|
+
|
40
|
+
@method = method
|
41
|
+
@address = address.to_s
|
42
|
+
end
|
43
|
+
|
44
|
+
def ==(other)
|
45
|
+
other = self.class.convert(other)
|
46
|
+
method == other.method && address == other.address
|
47
|
+
end
|
48
|
+
|
49
|
+
def to_s
|
50
|
+
address
|
51
|
+
end
|
52
|
+
|
53
|
+
PathError = Class.new StandardError
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
module Kernel
|
58
|
+
def Path(*args)
|
59
|
+
::MenuMaker::Path.convert(args)
|
60
|
+
end
|
61
|
+
end
|
data/lib/menu_maker/version.rb
CHANGED