/
navigation.rb
55 lines (46 loc) · 1.33 KB
/
navigation.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
module Menumatic
module Navigation
class Base
include ActionView::Helpers
@@navigations = {}
attr_accessor :id, :root
class << self
def navigate_to(label, destination, options = {})
if block_given?
item = self.get_instance.root.navigate_to(label, destination, options, &Proc.new)
else
item = self.get_instance.root.navigate_to(label, destination, options)
end
end
def group(id)
if block_given?
group = self.get_instance.root.group(id, &Proc.new)
else
group = self.get_instance.root.group(id)
end
end
def get_instance
id = self.name.split("Navigation").first.underscore.to_sym
@@navigations[id] = self.new(id) unless @@navigations.has_key?(id)
@@navigations[id]
end
def get(id)
unless @@navigations.has_key?(id)
Module.const_get("#{id.to_s.camelize}Navigation").get_instance
end
@@navigations[id]
end
def destroy_all
@@navigations = {}
end
end
def initialize(id)
self.id = id
self.root = Menumatic::Navigation::Item::Group.new("#{id}_root".to_sym)
end
def items
self.root.items
end
end
end
end