module Geri module Config class MenuItem attr_reader :title, :priority, :is_parent, :menu_items, :icon 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 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 def path "#{Geri::Config.admin_path}#{@path}" end def to_partial_path 'shared/menu_item' end end end end