activemenu 0.3.0 → 0.4.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fb819feb88597e6bd129107d3074049b45a3ef43
4
- data.tar.gz: f36bf14c024fc760fa45f3d0f9cb498e5f5227d4
3
+ metadata.gz: 2f5aa010d8d62f74c8feaeae635875b296ed144f
4
+ data.tar.gz: 247873f2e994ba74026223b77763f6fe595f18e2
5
5
  SHA512:
6
- metadata.gz: 6b66deca34cde3e4280f93f9158c6580fb0d739d85dc53bb8ef7a1e54528eb006312927697d5a450e517913cbc8ddc9634a89afb3796e6fb40697e0591f15352
7
- data.tar.gz: 8d80aa5c46cf5dec9b4f48be1c7409db8bdf35be23da4de4f62bcb4e0b626ba55663252a454bec1c0f34a27c1694a21fe106fa7f24d362c7a465a92d64675f73
6
+ metadata.gz: 176346f8915333413ec023f744680092bfedfa7707934a682c1f7c20e96f66aa9c02332ced6d3433c8bf8f374362e6d02dd2ad75f3c8ff522ace72ece19e18ad
7
+ data.tar.gz: 75856397839244d9dc73fc64ebc0048fbdd9c4e07be4ddead72c9ff5e5204c45d81449bf7e4b67b6108c736f4f11fb1d17f5263a4d10d9ff33c645311bf5cbc5
data/README.md CHANGED
@@ -20,11 +20,44 @@ Or install it yourself as:
20
20
 
21
21
  ## Usage
22
22
 
23
+ ### Creating menus objects
24
+
25
+ ```ruby
26
+ require 'active_menu'
27
+ ActiveMenu::create(:mymenu)
28
+ #....
29
+ # In another gem you can use
30
+ @menu = ActiveMenu::get(:mymenu).submenu do |sub|
31
+ sub.content == 'My content'
32
+ end
33
+ ```
34
+ ### exists?
35
+ ```ruby
36
+ ActiveMenu::create(:someid)
37
+ ActiveMenu::exists?(:someid) # == true
38
+ ActiveMenu::exists?(:this_id_doesnt_exists) # == false
39
+ ```
40
+
41
+
42
+ ### Set options to the menu
43
+ These options are write to a hash, that you can use with other gem to render it.
23
44
  ```ruby
24
- @menu = ActiveMenu::create(:mymenu)
45
+ @menu = ActiveMenu::get(:someid)
46
+ @menu.options[:tag] = :div
47
+ @menu.options[:myoptions] = 'myvalue'
48
+ ```
49
+
50
+ ### Get the menu
51
+ ```ruby
52
+ # You can retrieve the menu instance with the method get but you can use a block too.
53
+ @menu = ActiveMenu::get(:someid)
54
+ ActiveMenu::get(:someid) do |menu|
55
+ menu.id # The menu id
56
+ end
25
57
  ```
26
58
 
27
59
 
60
+ ### Nested menus
28
61
  ```ruby
29
62
  @menu = ActiveMenu::Menu.new(:mainmenu, 'http://example.com')
30
63
  # def initialize(id, href = nil, content=nil, submenus=[], parent=nil, &block) .... yield(self) if block_given?
@@ -1,22 +1,23 @@
1
1
  class ActiveMenu::Menu
2
2
 
3
- attr_accessor :id, :href, :content, :submenus, :parent
3
+ attr_accessor :id, :href, :content, :submenus, :parent, :options
4
4
 
5
- def initialize(id, href = nil, content=nil, submenus=[], parent=nil, &block)
5
+ def initialize(id, href = nil, content=nil, options={}, &block)
6
6
  @id = id.to_sym
7
7
  @href = href
8
- @submenus = []
9
8
  @content = content
9
+ @submenus = []
10
+ @options = options
10
11
 
11
12
  #sets the parent
12
13
  submenus.each {|s| s.parent = self }
13
14
  @submenus = submenus
14
- @parent = parent
15
15
  yield(self) if block_given?
16
16
  end
17
17
 
18
- def submenu(id, href, content=nil, submenus=[], &block)
19
- sm = self.class.new(id, href, content, submenus, self, &block)
18
+ def submenu(id, href, content=nil, options={}, &block)
19
+ sm = self.class.new(id, href, content, options, &block)
20
+ sm.parent = self
20
21
  @submenus << sm
21
22
  sm
22
23
  end
@@ -18,9 +18,24 @@ class ActiveMenu::Registry
18
18
  @menus = []
19
19
  end
20
20
 
21
- def get(id)
21
+ def get(id, &block)
22
22
  id = id.to_sym
23
- @menus.select {|m| m.id == id}.first
23
+ selected = @menus.select {|m| m.id == id}
24
+ if selected.length >= 1
25
+ yield(selected.first) if block_given?
26
+ selected.first
27
+ else
28
+ false
29
+ end
30
+ end
31
+
32
+ def exists?(id)
33
+ id = id.to_sym
34
+ if self.get(id)
35
+ true
36
+ else
37
+ false
38
+ end
24
39
  end
25
40
 
26
41
  end
@@ -1,3 +1,3 @@
1
1
  module ActiveMenu
2
- VERSION = "0.3.0"
2
+ VERSION = "0.4.0"
3
3
  end
data/lib/active_menu.rb CHANGED
@@ -16,8 +16,12 @@ module ActiveMenu
16
16
  self.registry.reset
17
17
  end
18
18
 
19
- def self.get(id)
20
- self.registry.get(id)
19
+ def self.get(id, &block)
20
+ self.registry.get(id, &block)
21
+ end
22
+
23
+ def self.exists?(id)
24
+ self.registry.exists?(id)
21
25
  end
22
26
 
23
27
  end
@@ -9,6 +9,8 @@ describe ActiveMenu::Menu do
9
9
  it {should respond_to(:content)}
10
10
  it {should respond_to(:submenus)}
11
11
  it {should respond_to(:parent)}
12
+ it {should respond_to(:options)}
13
+
12
14
 
13
15
  its(:submenus) {should be_a(Array)}
14
16
 
@@ -17,6 +19,8 @@ describe ActiveMenu::Menu do
17
19
  @menu = ActiveMenu::Menu.new(:idtest, "http://example.com", "My menu")
18
20
  end
19
21
 
22
+ #it 'can spec'
23
+
20
24
  it 'has the right attributes values' do
21
25
  @menu.content.should == 'My menu'
22
26
  @menu.id.should == :idtest
@@ -53,4 +57,12 @@ describe ActiveMenu::Menu do
53
57
 
54
58
  end
55
59
 
60
+
61
+ it 'can add options to a hash' do
62
+ @menu.options[:tag] = :div
63
+ @menu.options[:tag].should == :div
64
+ @menu.options[:tag] = :ul
65
+ @menu.options[:tag].should == :ul
66
+ end
67
+
56
68
  end
@@ -5,6 +5,11 @@ describe 'ActiveMenu::Registry' do
5
5
  it {should respond_to(:menus)}
6
6
  it {should be_a_kind_of(Singleton)}
7
7
 
8
+
9
+ before :each do
10
+ ActiveMenu::Registry.instance.reset
11
+ end
12
+
8
13
  it 'can reset the menus to zero' do
9
14
  ActiveMenu::Registry.instance.create(:idmenu, 'http://example.com')
10
15
  ActiveMenu::Registry.instance.menus.length == 1
@@ -12,4 +17,11 @@ describe 'ActiveMenu::Registry' do
12
17
  ActiveMenu::Registry.instance.menus.length == 0
13
18
  end
14
19
 
20
+ it 'can get a menu and yield it to a block' do
21
+ ActiveMenu::Registry.instance.create(:idmenu, 'http://example.com')
22
+ ActiveMenu::get(:idmenu) do |m|
23
+ m.id.should == :idmenu
24
+ end
25
+ end
26
+
15
27
  end
@@ -24,5 +24,11 @@ describe ActiveMenu do
24
24
  m2 = ActiveMenu::get('admin-nav')
25
25
  m1.should == m2
26
26
  end
27
-
27
+
28
+ it 'can check if a menu exists.' do
29
+ ActiveMenu::create(:someid)
30
+ ActiveMenu::exists?(:someid).should == true
31
+ ActiveMenu::exists?(:this_id_doesnt_exists).should == false
32
+ end
33
+
28
34
  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.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sadjow Medeiros Leão