activemenu 0.5.0 → 0.6.0
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 +2 -3
- data/lib/active_menu/menu.rb +36 -15
- data/lib/active_menu/registry.rb +2 -2
- data/lib/active_menu/version.rb +1 -1
- data/lib/active_menu.rb +2 -2
- data/spec/lib/active_menu/menu_spec.rb +9 -13
- data/spec/lib/active_menu_spec.rb +1 -1
- 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: 51d11e38637d249f618d8dbf23bece1b45ae651a
|
4
|
+
data.tar.gz: 6807d881dd022660e1da7ef9c9dc54580bc7d04d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 037342b6f525a12049b8a5c47755ed2d9b850fb9bfa0604da17b3abce1f4ff6b8c061c296d619c0d1e20211076ac57ede3920dc8df11468935912feb654d028e
|
7
|
+
data.tar.gz: 84e5c66118e5cf2d2fdd87bd314e1d696575cbc99a52c5a6b198a325aca51be0a1bdbcfc611bea727f87cb524a703d4730823fede5e32dcfe8fc78d9a1a4f165
|
data/README.md
CHANGED
@@ -4,7 +4,7 @@
|
|
4
4
|
[](https://gemnasium.com/sadjow/activemenu)
|
5
5
|
[](https://codeclimate.com/github/sadjow/activemenu)
|
6
6
|
|
7
|
-
A toolkit to create menus with multi level and a Domain Specific
|
7
|
+
A toolkit to create menus with multi level and a Domain Specific Language(DSL) for Menus.
|
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
|
|
@@ -45,7 +45,6 @@ end
|
|
45
45
|
### Get the menu
|
46
46
|
You can retrieve the menu instance with the method get...
|
47
47
|
```ruby
|
48
|
-
#
|
49
48
|
@menu = ActiveMenu::get(:someid)
|
50
49
|
```
|
51
50
|
|
@@ -65,7 +64,7 @@ These options are write to a hash, that you can use with other gem to render it.
|
|
65
64
|
@menu.options[:myoptions] = 'myvalue'
|
66
65
|
```
|
67
66
|
|
68
|
-
## Standard DSL (Domain
|
67
|
+
## Standard DSL (Domain Specific Language) options
|
69
68
|
|
70
69
|
To facilitate the creating of menus, there are some methods to help you organize the options standard.
|
71
70
|
|
data/lib/active_menu/menu.rb
CHANGED
@@ -1,33 +1,54 @@
|
|
1
1
|
class ActiveMenu::Menu
|
2
2
|
|
3
|
-
attr_accessor :id, :
|
3
|
+
attr_accessor :id, :submenus, :parent, :options
|
4
4
|
|
5
|
-
def initialize(id,
|
5
|
+
def initialize(id, options={}, &block)
|
6
6
|
@id = id.to_sym
|
7
|
-
@href = href
|
8
|
-
@content = content
|
9
|
-
@submenus = []
|
10
7
|
@options = options
|
11
|
-
|
12
|
-
#sets the parent
|
13
|
-
submenus.each {|s| s.parent = self }
|
14
|
-
@submenus = submenus
|
8
|
+
@submenus = []
|
15
9
|
yield(self) if block_given?
|
16
10
|
end
|
17
11
|
|
18
|
-
def submenu(id,
|
19
|
-
sm = self.class.new(id,
|
12
|
+
def submenu(id, options={}, &block)
|
13
|
+
sm = self.class.new(id, options, &block)
|
20
14
|
sm.parent = self
|
21
15
|
@submenus << sm
|
22
16
|
sm
|
23
17
|
end
|
24
18
|
|
25
|
-
def
|
26
|
-
if
|
19
|
+
def text(value = nil)
|
20
|
+
if value.nil?
|
21
|
+
@options[:text]
|
22
|
+
else
|
23
|
+
value = value.to_sym
|
24
|
+
@options[:text] = value
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def text=(value)
|
29
|
+
self.text(value)
|
30
|
+
end
|
31
|
+
|
32
|
+
def href(value = nil)
|
33
|
+
if value.nil?
|
34
|
+
@options[:href]
|
35
|
+
else
|
36
|
+
value = value.to_sym
|
37
|
+
@options[:href] = value
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def href=(value)
|
42
|
+
self.href(value)
|
43
|
+
end
|
44
|
+
|
45
|
+
|
46
|
+
def tag(value=nil)
|
47
|
+
if value.nil?
|
27
48
|
@options[:tag]
|
28
49
|
else
|
29
|
-
|
30
|
-
@options[:tag] =
|
50
|
+
value = value.to_sym
|
51
|
+
@options[:tag] = value
|
31
52
|
end
|
32
53
|
end
|
33
54
|
|
data/lib/active_menu/registry.rb
CHANGED
data/lib/active_menu/version.rb
CHANGED
data/lib/active_menu.rb
CHANGED
@@ -5,36 +5,32 @@ describe ActiveMenu::Menu do
|
|
5
5
|
subject {ActiveMenu::Menu.new(:idtest)}
|
6
6
|
|
7
7
|
it {should respond_to(:id)}
|
8
|
-
it {should respond_to(:href)}
|
9
|
-
it {should respond_to(:content)}
|
10
8
|
it {should respond_to(:submenus)}
|
11
9
|
it {should respond_to(:parent)}
|
12
10
|
it {should respond_to(:options)}
|
13
|
-
|
14
|
-
|
11
|
+
|
15
12
|
its(:submenus) {should be_a(Array)}
|
16
13
|
|
17
|
-
|
18
14
|
before :each do
|
19
|
-
@menu = ActiveMenu::Menu.new(:idtest, "http://example.com", "My menu")
|
15
|
+
@menu = ActiveMenu::Menu.new(:idtest, href: "http://example.com", text: "My menu")
|
20
16
|
end
|
21
17
|
|
22
18
|
#it 'can spec'
|
23
19
|
|
24
20
|
it 'has the right attributes values' do
|
25
|
-
@menu.
|
21
|
+
@menu.text.should == 'My menu'
|
26
22
|
@menu.id.should == :idtest
|
27
23
|
@menu.href.should == "http://example.com"
|
28
24
|
end
|
29
25
|
|
30
26
|
it 'can add submenus' do
|
31
|
-
@submenu = ActiveMenu::Menu.new(:mysubmenu, '#an_anchor', "My submenu")
|
27
|
+
@submenu = ActiveMenu::Menu.new(:mysubmenu, href: '#an_anchor', text: "My submenu")
|
32
28
|
@menu.submenus << @submenu
|
33
29
|
@menu.submenus.length.should == 1
|
34
30
|
end
|
35
31
|
|
36
32
|
it 'can add submenus directly' do
|
37
|
-
submenu = @menu.submenu(:mysubmenu, '#an_anchor', "My submenu")
|
33
|
+
submenu = @menu.submenu(:mysubmenu, href: '#an_anchor', text: "My submenu")
|
38
34
|
@menu.submenus.length.should == 1
|
39
35
|
submenu.parent.should == @menu
|
40
36
|
submenu.parent.id.should == @menu.id
|
@@ -42,12 +38,12 @@ describe ActiveMenu::Menu do
|
|
42
38
|
|
43
39
|
|
44
40
|
it 'have a flexible DSL for menus' do
|
45
|
-
@menu.submenu(:mysubmenu, "test") do |sm|
|
41
|
+
@menu.submenu(:mysubmenu, text: "test") do |sm|
|
46
42
|
@sm = sm
|
47
|
-
sm.
|
48
|
-
sm.submenu(:mysubsubmenu, 'test 2') do |ssm|
|
43
|
+
sm.text = 'My submenu'
|
44
|
+
sm.submenu(:mysubsubmenu, text: 'test 2') do |ssm|
|
49
45
|
@ssm = ssm
|
50
|
-
ssm.
|
46
|
+
ssm.text == 'My subsubmenu'
|
51
47
|
end
|
52
48
|
end
|
53
49
|
|
@@ -15,7 +15,7 @@ describe ActiveMenu do
|
|
15
15
|
end
|
16
16
|
|
17
17
|
it 'can create a menu directly' do
|
18
|
-
ActiveMenu::create(:someid, 'http://example.com').should be_a_kind_of(ActiveMenu::Menu)
|
18
|
+
ActiveMenu::create(:someid, href: 'http://example.com').should be_a_kind_of(ActiveMenu::Menu)
|
19
19
|
ActiveMenu::registry.menus.length.should == 1
|
20
20
|
end
|
21
21
|
|