activemenu 0.7.0 → 0.7.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 93755f43aa9964d6ccdf71ecc44bffc069ac70df
4
- data.tar.gz: 64c21a172ed17c5d7f116f05e6a4a640ad74bea6
3
+ metadata.gz: 8e3e9869a0e933986306dd0320657357d461240e
4
+ data.tar.gz: 9fbb3a230d6691df88b04fe5b2ecf47c717b6fd7
5
5
  SHA512:
6
- metadata.gz: 25ff9d89be8614cc30fcede3e61b98e334637bbaf2259e41fe3ed99e0db089d30eeb836394d25e15462e288ad2ddff01eb87b90a764e5760af5fc0a204700d12
7
- data.tar.gz: 4fb6b175ec9878e116708362285456b639bcec476e4d52a84061036a7bd6fb868355bcde8c08e6e89dc1dd911c02a1f28c274f6e879e351e88f53b32dcc3ef91
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).submenu do |sub|
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.submenu(:mysubmenu, href: "test") do |sm|
87
- sm.text 'My submenu'
88
- sm.submenu(:mysubsubmenu, href:'test 2') do |ssm|
89
- ssm.text 'My subsubmenu'
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.
@@ -1,11 +1,15 @@
1
1
  class ActiveMenu::Menu < ActiveMenu::Node
2
2
 
3
- def text(value = nil)
3
+ def text(value=nil)
4
4
  self.option(:text, value)
5
5
  end
6
6
 
7
- def href(value = nil)
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
@@ -1,3 +1,3 @@
1
1
  module ActiveMenu
2
- VERSION = "0.7.0"
2
+ VERSION = "0.7.1"
3
3
  end
@@ -73,4 +73,11 @@ describe ActiveMenu::Menu do
73
73
  @menu.tag.should == :div
74
74
  end
75
75
 
76
+ it 'can set a visible options' do
77
+ @menu.visible false
78
+ @menu.visible.should == false
79
+ @menu.visible true
80
+ @menu.visible.should == true
81
+ end
82
+
76
83
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activemenu
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.0
4
+ version: 0.7.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sadjow Medeiros Leão