remove trailing white-spaces from lib/redmine/menu_manager.rb.
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@6468 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
parent
2ea231b9e6
commit
75ce76cd74
|
@ -1,16 +1,16 @@
|
|||
# redMine - project management software
|
||||
# Copyright (C) 2006-2007 Jean-Philippe Lang
|
||||
# Redmine - project management software
|
||||
# Copyright (C) 2006-2011 Jean-Philippe Lang
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
# as published by the Free Software Foundation; either version 2
|
||||
# of the License, or (at your option) any later version.
|
||||
#
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
@ -22,7 +22,7 @@ module TreeNodePatch
|
|||
def self.included(base)
|
||||
base.class_eval do
|
||||
attr_reader :last_items_count
|
||||
|
||||
|
||||
alias :old_initilize :initialize
|
||||
def initialize(name, content = nil)
|
||||
old_initilize(name, content)
|
||||
|
@ -31,7 +31,7 @@ module TreeNodePatch
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
module InstanceMethods
|
||||
# Adds the specified child node to the receiver node. The child node's
|
||||
# parent is set to be the receiver. The child is added as the first child in
|
||||
|
@ -105,7 +105,7 @@ module Redmine
|
|||
module MenuManager
|
||||
class MenuError < StandardError #:nodoc:
|
||||
end
|
||||
|
||||
|
||||
module MenuController
|
||||
def self.included(base)
|
||||
base.extend(ClassMethods)
|
||||
|
@ -114,13 +114,13 @@ module Redmine
|
|||
module ClassMethods
|
||||
@@menu_items = Hash.new {|hash, key| hash[key] = {:default => key, :actions => {}}}
|
||||
mattr_accessor :menu_items
|
||||
|
||||
|
||||
# Set the menu item name for a controller or specific actions
|
||||
# Examples:
|
||||
# * menu_item :tickets # => sets the menu name to :tickets for the whole controller
|
||||
# * menu_item :tickets, :only => :list # => sets the menu name to :tickets for the 'list' action only
|
||||
# * menu_item :tickets, :only => [:list, :show] # => sets the menu name to :tickets for 2 actions only
|
||||
#
|
||||
#
|
||||
# The default menu item name for a controller is controller_name by default
|
||||
# Eg. the default menu item name for ProjectsController is :projects
|
||||
def menu_item(id, options = {})
|
||||
|
@ -132,17 +132,17 @@ module Redmine
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def menu_items
|
||||
self.class.menu_items
|
||||
end
|
||||
|
||||
|
||||
# Returns the menu item name according to the current action
|
||||
def current_menu_item
|
||||
@current_menu_item ||= menu_items[controller_name.to_sym][:actions][action_name.to_sym] ||
|
||||
menu_items[controller_name.to_sym][:default]
|
||||
end
|
||||
|
||||
|
||||
# Redirects user to the menu item of the given project
|
||||
# Returns false if user is not authorized
|
||||
def redirect_to_project_menu_item(project, name)
|
||||
|
@ -154,18 +154,18 @@ module Redmine
|
|||
false
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
module MenuHelper
|
||||
# Returns the current menu item name
|
||||
def current_menu_item
|
||||
@controller.current_menu_item
|
||||
end
|
||||
|
||||
|
||||
# Renders the application main menu
|
||||
def render_main_menu(project)
|
||||
render_menu((project && !project.new_record?) ? :project_menu : :application_menu, project)
|
||||
end
|
||||
|
||||
|
||||
def display_main_menu?(project)
|
||||
menu_name = project && !project.new_record? ? :project_menu : :application_menu
|
||||
Redmine::MenuManager.items(menu_name).size > 1 # 1 element is the root
|
||||
|
@ -224,7 +224,7 @@ module Redmine
|
|||
# Tree nodes support #each so we need to do object detection
|
||||
if unattached_children.is_a? Array
|
||||
unattached_children.each do |child|
|
||||
child_html << content_tag(:li, render_unattached_menu_item(child, project))
|
||||
child_html << content_tag(:li, render_unattached_menu_item(child, project))
|
||||
end
|
||||
else
|
||||
raise MenuError, ":child_menus must be an array of MenuItems"
|
||||
|
@ -245,7 +245,7 @@ module Redmine
|
|||
menu_item.html_options)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def menu_items_for(menu, project=nil)
|
||||
items = []
|
||||
Redmine::MenuManager.items(menu).root.children.each do |node|
|
||||
|
@ -292,7 +292,7 @@ module Redmine
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
class << self
|
||||
def map(menu_name)
|
||||
@items ||= {}
|
||||
|
@ -303,21 +303,21 @@ module Redmine
|
|||
mapper
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def items(menu_name)
|
||||
@items[menu_name.to_sym] || Tree::TreeNode.new(:root, {})
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
class Mapper
|
||||
def initialize(menu, items)
|
||||
items[menu] ||= Tree::TreeNode.new(:root, {})
|
||||
@menu = menu
|
||||
@menu_items = items[menu]
|
||||
end
|
||||
|
||||
|
||||
@@last_items_count = Hash.new {|h,k| h[k] = 0}
|
||||
|
||||
|
||||
# Adds an item at the end of the menu. Available options:
|
||||
# * param: the parameter name that is used for the project id (default is :id)
|
||||
# * if: a Proc that is called before rendering the item, the item is displayed only if it returns true
|
||||
|
@ -364,14 +364,14 @@ module Redmine
|
|||
else
|
||||
target_root.add(MenuItem.new(name, url, options))
|
||||
end
|
||||
|
||||
|
||||
elsif options[:last] # don't delete, needs to be stored
|
||||
target_root.add_last(MenuItem.new(name, url, options))
|
||||
else
|
||||
target_root.add(MenuItem.new(name, url, options))
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
# Removes a menu item
|
||||
def delete(name)
|
||||
if found = self.find(name)
|
||||
|
@ -396,11 +396,11 @@ module Redmine
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
class MenuItem < Tree::TreeNode
|
||||
include Redmine::I18n
|
||||
attr_reader :name, :url, :param, :condition, :parent, :child_menus, :last
|
||||
|
||||
|
||||
def initialize(name, url, options)
|
||||
raise ArgumentError, "Invalid option :if for menu item '#{name}'" if options[:if] && !options[:if].respond_to?(:call)
|
||||
raise ArgumentError, "Invalid option :html for menu item '#{name}'" if options[:html] && !options[:html].is_a?(Hash)
|
||||
|
@ -419,7 +419,7 @@ module Redmine
|
|||
@last = options[:last] || false
|
||||
super @name.to_sym
|
||||
end
|
||||
|
||||
|
||||
def caption(project=nil)
|
||||
if @caption.is_a?(Proc)
|
||||
c = @caption.call(project).to_s
|
||||
|
@ -433,7 +433,7 @@ module Redmine
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def html_options(options={})
|
||||
if options[:selected]
|
||||
o = @html_options.dup
|
||||
|
@ -443,6 +443,6 @@ module Redmine
|
|||
@html_options
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue