Class: Geri::Config::MenuItem

Inherits:
Object
  • Object
show all
Defined in:
lib/geri/config/menu_item.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(title, path_or_options = nil, options = {}) ⇒ MenuItem

Returns a new instance of MenuItem.



6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/geri/config/menu_item.rb', line 6

def initialize(title, path_or_options=nil, options={})
  if !path_or_options || path_or_options.is_a?(Hash)
    options = path_or_options if path_or_options
    @is_parent = true
  else
    @path = path_or_options
  end
  @icon       = options[:icon]
  @title      = title
  @priority   = options[:priority] || 0
  @menu_items = []
end

Instance Attribute Details

#iconObject (readonly)

Returns the value of attribute icon.



4
5
6
# File 'lib/geri/config/menu_item.rb', line 4

def icon
  @icon
end

#is_parentObject (readonly)

Returns the value of attribute is_parent.



4
5
6
# File 'lib/geri/config/menu_item.rb', line 4

def is_parent
  @is_parent
end

Returns the value of attribute menu_items.



4
5
6
# File 'lib/geri/config/menu_item.rb', line 4

def menu_items
  @menu_items
end

#priorityObject (readonly)

Returns the value of attribute priority.



4
5
6
# File 'lib/geri/config/menu_item.rb', line 4

def priority
  @priority
end

#titleObject (readonly)

Returns the value of attribute title.



4
5
6
# File 'lib/geri/config/menu_item.rb', line 4

def title
  @title
end

Instance Method Details

#pathObject



25
26
27
# File 'lib/geri/config/menu_item.rb', line 25

def path
  "#{Geri::Config.admin_path}#{@path}"
end

#register_menu_item(title, path_or_options = nil, options = {}) {|item| ... } ⇒ Object

Yields:

  • (item)


19
20
21
22
23
# File 'lib/geri/config/menu_item.rb', line 19

def register_menu_item(title, path_or_options=nil, options={})
  self.menu_items << item = MenuItem.new(title, path_or_options, options)
  yield item if block_given?
  self.menu_items.sort! { |a, b| a.priority <=> b.priority }
end

#to_partial_pathObject



29
30
31
# File 'lib/geri/config/menu_item.rb', line 29

def to_partial_path
  'shared/menu_item'
end