activemenu 0.7.0 → 0.7.1
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 +46 -6
- data/lib/active_menu/menu.rb +6 -2
- data/lib/active_menu/version.rb +1 -1
- data/spec/lib/active_menu/menu_spec.rb +7 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8e3e9869a0e933986306dd0320657357d461240e
|
4
|
+
data.tar.gz: 9fbb3a230d6691df88b04fe5b2ecf47c717b6fd7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f2df392ecbf6c5358e0357a609a1edcd02668f164107362f78a8269cf122992976f674f06d1ad91e5958e6aac654efaa54c132e606c7c407125440a5179311f9
|
7
|
+
data.tar.gz: 4f9882c81f1dbebde2affd1df028b7fb7e41dddd4e87375b9405a5dc9f7f7eff65871f052e0ffcf9a9d8ba2ae0bf6651ac0d8c6d10f77912587e8b63bf125883
|
data/README.md
CHANGED
@@ -8,6 +8,32 @@ A toolkit to create menus with multi level and a Domain Specific Language(DSL) f
|
|
8
8
|
It's extremely Object Oriented. It still doesn't have code for render, but you can combine it with
|
9
9
|
other renderer like simple-navigation or you own.
|
10
10
|
|
11
|
+
## Initial example
|
12
|
+
```ruby
|
13
|
+
ActiveMenu::create('admix-nav') do |nav|
|
14
|
+
|
15
|
+
nav.child :dashboard do |dashboard|
|
16
|
+
dashboard.text Proc.new { t('dashboard.dashboard') }
|
17
|
+
dashboard.href Proc.new { admix_root_url }
|
18
|
+
dashboard.option :icon, 'icon-flag'
|
19
|
+
end
|
20
|
+
|
21
|
+
nav.child :general do |general|
|
22
|
+
general.text Proc.new { t('general.general') }
|
23
|
+
general.option :icon, 'icon-flag'
|
24
|
+
general.visible Proc.new {current_user.has_role? :admin}
|
25
|
+
end
|
26
|
+
|
27
|
+
nav.child :content do |content|
|
28
|
+
content.text Proc.new { t('general.general') }
|
29
|
+
content.option :icon, 'icon-flag'
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
```
|
36
|
+
|
11
37
|
## Installation
|
12
38
|
|
13
39
|
Add this line to your application's Gemfile:
|
@@ -24,13 +50,13 @@ Or install it yourself as:
|
|
24
50
|
|
25
51
|
## Usage
|
26
52
|
|
27
|
-
### Creating menus objects
|
53
|
+
### Creating menus objects in the registry
|
28
54
|
|
29
55
|
```ruby
|
30
56
|
ActiveMenu::create(:mymenu)
|
31
57
|
#....
|
32
58
|
# In another gem you can use
|
33
|
-
@menu = ActiveMenu::get(:mymenu).
|
59
|
+
@menu = ActiveMenu::get(:mymenu).child do |sub|
|
34
60
|
sub.content == 'My content'
|
35
61
|
end
|
36
62
|
```
|
@@ -67,6 +93,20 @@ These options are write to a hash, that you can use with other gem to render it.
|
|
67
93
|
|
68
94
|
To facilitate the creating of menus, there are some methods to help you organize the options standard.
|
69
95
|
|
96
|
+
### visible(value=nil)
|
97
|
+
You can pass a variable or a Proc to be executed to the visible method.
|
98
|
+
```ruby
|
99
|
+
ActiveMenu::create('admix-nav') do |nav|
|
100
|
+
nav.child :general do |general|
|
101
|
+
general.text Proc.new { t('general.general') }
|
102
|
+
general.option :icon, 'icon-flag'
|
103
|
+
general.visible Proc.new {current_user.has_role? :admin}
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
end
|
108
|
+
```
|
109
|
+
|
70
110
|
### tag(value=nil)
|
71
111
|
You can set the tag for the menu element or can retrieve it.
|
72
112
|
```ruby
|
@@ -83,10 +123,10 @@ You can set the tag for the menu element or can retrieve it.
|
|
83
123
|
```ruby
|
84
124
|
@menu = ActiveMenu::Menu.new(:mainmenu, href: 'http://example.com')
|
85
125
|
# def initialize(id, options={}, &block) .... yield(self) if block_given?
|
86
|
-
@menu.
|
87
|
-
sm.text 'My
|
88
|
-
sm.
|
89
|
-
ssm.text 'My
|
126
|
+
@menu.child(:mychild, href: "test") do |sm|
|
127
|
+
sm.text 'My child'
|
128
|
+
sm.child(:mysubchild, href:'test 2') do |ssm|
|
129
|
+
ssm.text 'My subchild'
|
90
130
|
end
|
91
131
|
end
|
92
132
|
# Let's improve this DSL, contribute please.
|
data/lib/active_menu/menu.rb
CHANGED
@@ -1,11 +1,15 @@
|
|
1
1
|
class ActiveMenu::Menu < ActiveMenu::Node
|
2
2
|
|
3
|
-
def text(value
|
3
|
+
def text(value=nil)
|
4
4
|
self.option(:text, value)
|
5
5
|
end
|
6
6
|
|
7
|
-
def href(value
|
7
|
+
def href(value=nil)
|
8
8
|
self.option(:href, value)
|
9
9
|
end
|
10
10
|
|
11
|
+
def visible(value=nil)
|
12
|
+
self.option(:visible, value)
|
13
|
+
end
|
14
|
+
|
11
15
|
end
|
data/lib/active_menu/version.rb
CHANGED