activemenu 0.7.2 → 0.8.0

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: c22b8b5f5b01e39ee5ffb0df99c998f19f94e4af
4
- data.tar.gz: 382480a2224021d487c14a1239b96b76a086af22
3
+ metadata.gz: ffa4c3df4c94a97fdaf3f21747ddb78597d4d246
4
+ data.tar.gz: f75a7d315fce8804b99f5db4e5c7fb09f5a8b567
5
5
  SHA512:
6
- metadata.gz: 04040de10d6bf50a21aa44b31d7845ac73530aff0c0b1564b0b9e39ae2ab23194442590d310eecc7f0ea1d9ba5e25f52b464eaa35a79d2853c37335a78761740
7
- data.tar.gz: 4fb36fc5737a80c3f2fff5f683b601fddcb5ccbcd065edb2d9485551e35654b45b923248f90ae266fdaad0b3e7f970cb356dce0d0942f7afb17f23b8b4a3a4b0
6
+ metadata.gz: 0645c982ed954205a7cacd2ddce21e1578b00ff23e01f65d47ca68350a3ddbf352b1e216d848b2114d526f31e59929eafc54a3677fcaeeb21e82970f6d5a5eba
7
+ data.tar.gz: 312ec1088cacd38a55cc07a8bcb0dd108f8ee0c6d76eff91706969647cefaad9b4ec825b7cd161137a57a1a7a995b882096174246c8bb362abe1d905ffbc37dc
data/README.md CHANGED
@@ -1,37 +1,50 @@
1
- # ActiveMenu
1
+ ![ActiveMenu Logo](https://raw.github.com/sadjow/activemenu/master/activemenu_logo.png)
2
2
 
3
+ [![Gem Version](https://fury-badge.herokuapp.com/rb/activemenu.png)](http://badge.fury.io/rb/activemenu)
3
4
  [![Build Status](https://travis-ci.org/sadjow/activemenu.png)](https://travis-ci.org/sadjow/activemenu)
4
5
  [![Dependency Status](https://gemnasium.com/sadjow/activemenu.png)](https://gemnasium.com/sadjow/activemenu)
5
6
  [![Code Climate](https://codeclimate.com/github/sadjow/activemenu.png)](https://codeclimate.com/github/sadjow/activemenu)
6
7
 
7
- A toolkit to create menus with multi level and a Domain Specific Language(DSL) for Menus.
8
+ Create menus with multi-level and a Domain Specific Language (DSL) for menus.
8
9
  It's extremely Object Oriented. It still doesn't have code for render, but you can combine it with
9
- other renderer like simple-navigation or you own.
10
+ other mechanism for rendering, like simple-navigation or other.
11
+
12
+ ## Semantic Versioning (http://semver.org/)
13
+ This gem is following the [Semantic Versioning](http://semver.org/)
14
+
15
+ ## Features
16
+ * Compatible with any application or framework.
17
+ * Singleton registry for menus (ActiveMenu::Registry), you can define menus anywhere. (But, use your conscience to a good design.)
18
+ * Domain Specific Language
19
+ * You can define the menu along multiple gems(like plugins of Rails)
20
+
21
+ ## Some wiki
22
+ [Using simple-navigation with activemenu](https://github.com/sadjow/activemenu/wiki/Using-simple-navigation-for-render-the-activemenu)
10
23
 
11
24
  ## Initial example
12
25
  ```ruby
13
26
  ActiveMenu::create('admix-nav') do |nav|
14
-
27
+
15
28
  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'
29
+ dashboard.text = Proc.new { t('dashboard.dashboard') }
30
+ dashboard.href = Proc.new { admix_root_url }
31
+ dashboard.icon = 'icon-flag'
19
32
  end
20
33
 
21
34
  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}
35
+ general.text = Proc.new { t('general.general') }
36
+ general.icon = 'icon-flag'
37
+ general.href = 'javascript:;'
38
+ general.visible = Proc.new {current_user.has_role?(:admin)}
25
39
  end
26
40
 
27
41
  nav.child :content do |content|
28
- content.text Proc.new { t('general.general') }
29
- content.option :icon, 'icon-flag'
42
+ content.text = Proc.new { t('content.content') }
43
+ content.href = 'javascript:;'
44
+ content.icon = 'icon-flag'
30
45
  end
31
46
 
32
47
  end
33
-
34
- end
35
48
  ```
36
49
 
37
50
  ## Installation
@@ -57,7 +70,7 @@ ActiveMenu::create(:mymenu)
57
70
  #....
58
71
  # In another gem you can use
59
72
  @menu = ActiveMenu::get(:mymenu).child do |sub|
60
- sub.content == 'My content'
73
+ sub.content = 'My content'
61
74
  end
62
75
  ```
63
76
  ### exists?
@@ -90,8 +103,8 @@ or, you can use a block too and retrieve it as the first param.
90
103
  These options are write to a hash, that you can use with other gem to render it.
91
104
  ```ruby
92
105
  @menu = ActiveMenu::get(:someid)
93
- @menu.options[:tag] = :div
94
- @menu.options[:myoptions] = 'myvalue'
106
+ @menu.myoption = 'my value'
107
+ @menu.myoption2 = Proc.new { my_dynamic_method #that will run when I use this option }
95
108
  ```
96
109
 
97
110
  ## Standard DSL (Domain Specific Language) options
@@ -103,9 +116,9 @@ You can pass a variable or a Proc to be executed to the visible method.
103
116
  ```ruby
104
117
  ActiveMenu::create('admix-nav') do |nav|
105
118
  nav.child :general do |general|
106
- general.text Proc.new { t('general.general') }
107
- general.option :icon, 'icon-flag'
108
- general.visible Proc.new {current_user.has_role? :admin}
119
+ general.text = Proc.new { t('general.general') }
120
+ general.icon = 'icon-flag'
121
+ general.visible = Proc.new {current_user.has_role? :admin}
109
122
  end
110
123
  end
111
124
 
@@ -131,7 +144,7 @@ You can set the tag for the menu element or can retrieve it.
131
144
  @menu.child(:mychild, href: "test") do |sm|
132
145
  sm.text 'My child'
133
146
  sm.child(:mysubchild, href:'test 2') do |ssm|
134
- ssm.text 'My subchild'
147
+ ssm.text = 'My subchild'
135
148
  end
136
149
  end
137
150
  # Let's improve this DSL, contribute please.
Binary file
@@ -2,20 +2,7 @@ class ActiveMenu::Menu < ActiveMenu::Node
2
2
 
3
3
  def initialize(*args)
4
4
  super(*args)
5
- self.visible true
6
- end
7
-
8
-
9
- def text(value=nil)
10
- self.option(:text, value)
11
- end
12
-
13
- def href(value=nil)
14
- self.option(:href, value)
15
- end
16
-
17
- def visible(value=nil)
18
- self.option(:visible, value)
5
+ self.visible = true
19
6
  end
20
7
 
21
8
  end
@@ -19,10 +19,6 @@ class ActiveMenu::Node
19
19
  end
20
20
  end
21
21
 
22
- def tag(value=nil)
23
- self.option(:tag, value)
24
- end
25
-
26
22
  def child(id, options={}, &block)
27
23
  new_child = self.class.new(id, options)
28
24
  new_child.parent = self
@@ -65,5 +61,20 @@ class ActiveMenu::Node
65
61
  end
66
62
  end
67
63
 
64
+ def method_missing(method_name, *args)
65
+ unless respond_to?(method_name)
66
+ option_name = method_name.to_s.gsub("=", "").to_sym
67
+ match_eq = method_name.to_s.match(/^(\w)=/)
68
+ self.class.class_eval do
69
+ define_method method_name do |value=nil|
70
+ option(option_name, value)
71
+ end
72
+ end
73
+ send(method_name, *args)
74
+ else
75
+ send(method_name, *args)
76
+ end
77
+ end
78
+
68
79
 
69
80
  end
@@ -1,3 +1,3 @@
1
1
  module ActiveMenu
2
- VERSION = "0.7.2"
2
+ VERSION = "0.8.0"
3
3
  end
@@ -15,6 +15,13 @@ describe ActiveMenu::Menu do
15
15
  @menu = ActiveMenu::Menu.new(:idtest, href: "http://example.com", text: "My menu")
16
16
  end
17
17
 
18
+ it 'can define dynamic options' do
19
+ @menu.seila = :li
20
+ @menu.seila.should == :li
21
+ @menu.seila = :div
22
+ @menu.seila.should == :div
23
+ end
24
+
18
25
  it 'starts visible' do
19
26
  @menu.visible.should == true
20
27
  end
@@ -42,7 +49,7 @@ describe ActiveMenu::Menu do
42
49
  it 'have a flexible DSL for menus' do
43
50
  @menu.child(:mychild, text: "test") do |sm|
44
51
  @sm = sm
45
- sm.text 'My child'
52
+ sm.text = 'My child'
46
53
  sm.child(:mysubchild, text: 'test 2') do |ssm|
47
54
  @ssm = ssm
48
55
  ssm.text == 'My subchild'
@@ -64,22 +71,27 @@ describe ActiveMenu::Menu do
64
71
  end
65
72
 
66
73
  it 'can add a tag as a option' do
67
- @menu.tag :li
74
+ @menu.tag = :li
68
75
  @menu.options[:tag].should == :li
69
76
  end
70
77
 
71
78
  it 'can add and retrieve the tag name with the #tag method' do
72
- @menu.tag :li
79
+ @menu.tag = :li
73
80
  @menu.tag.should == :li
74
- @menu.tag :div
81
+ @menu.tag = :div
75
82
  @menu.tag.should == :div
76
83
  end
77
84
 
78
85
  it 'can set a visible options' do
79
- @menu.visible false
86
+ @menu.visible = false
80
87
  @menu.visible.should == false
81
- @menu.visible true
88
+ @menu.visible = true
82
89
  @menu.visible.should == true
83
90
  end
84
91
 
92
+ it 'can set a undefined method as a option' do
93
+ @menu.author = "Sadjow"
94
+ @menu.author.should == "Sadjow"
95
+ end
96
+
85
97
  end
@@ -34,10 +34,10 @@ describe ActiveMenu do
34
34
 
35
35
  it 'can create menus with lambdas' do
36
36
  ActiveMenu::create('admix-nav') do |nav|
37
- nav.tag :div
37
+ nav.tag = :div
38
38
  nav.child :dashboard do |d|
39
- d.text 'dashboard.dashboard'
40
- d.href lambda { admix_root_url }
39
+ d.text = 'dashboard.dashboard'
40
+ d.href = lambda { admix_root_url }
41
41
  d.option :icon, 'icon-flag'
42
42
  end
43
43
  end
@@ -49,10 +49,10 @@ describe ActiveMenu do
49
49
  before :each do
50
50
  @dashboard = nil
51
51
  @nav = ActiveMenu::create('admix-nav') do |nav|
52
- nav.tag :div
52
+ nav.tag = :div
53
53
  @dashboard = nav.child :dashboard do |d|
54
- d.text 'dashboard.dashboard'
55
- d.href lambda { admix_root_url }
54
+ d.text = 'dashboard.dashboard'
55
+ d.href = lambda { admix_root_url }
56
56
  d.option :icon, 'icon-flag'
57
57
  end
58
58
  end
@@ -72,7 +72,7 @@ describe ActiveMenu do
72
72
  nav.get(:dashboard) do |d|
73
73
  d.child :testchild do |sub|
74
74
  @testchild = sub
75
- sub.text "My child"
75
+ sub.text = "My child"
76
76
  end
77
77
  end
78
78
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activemenu
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.2
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sadjow Medeiros Leão
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-03-05 00:00:00.000000000 Z
11
+ date: 2013-03-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -52,6 +52,7 @@ files:
52
52
  - README.md
53
53
  - Rakefile
54
54
  - activemenu.gemspec
55
+ - activemenu_logo.png
55
56
  - lib/active_menu.rb
56
57
  - lib/active_menu/menu.rb
57
58
  - lib/active_menu/node.rb