Class: AndyAdmin::Menu

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/generators/andy_admin/templates/menu.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeMenu

Returns a new instance of Menu.



10
11
12
13
# File 'lib/generators/andy_admin/templates/menu.rb', line 10

def initialize
  @main_items = []
  @sub_items = []      
end

Class Method Details

.build(&block) ⇒ Object



5
6
7
8
# File 'lib/generators/andy_admin/templates/menu.rb', line 5

def self.build(&block)
  instance.instance_eval(&block)
  instance
end

Instance Method Details

#main(id, name, link = nil) ⇒ Object



15
16
17
# File 'lib/generators/andy_admin/templates/menu.rb', line 15

def main(id, name, link=nil)
  @main_items << {:name => name, :link => link, :id => id}
end

#main_items_each(current) ⇒ Object



23
24
25
26
27
28
# File 'lib/generators/andy_admin/templates/menu.rb', line 23

def main_items_each(current)
  @main_items.each do |item|
    css_class = (item[:id] == current ? "active" : "")
    yield(item[:name], item[:link], item[:id], css_class)
  end
end

#sub(id, name, link = nil) ⇒ Object



19
20
21
# File 'lib/generators/andy_admin/templates/menu.rb', line 19

def sub(id, name, link=nil)
  @sub_items << {:name => name, :link => link, :id => id}
end

#sub_items_each(current) ⇒ Object



30
31
32
33
34
35
# File 'lib/generators/andy_admin/templates/menu.rb', line 30

def sub_items_each(current)
  @sub_items.each do |item|
    css_class = (item[:id] == current ? "active" : "")
    yield(item[:name], item[:link], item[:id], css_class)
  end
end