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:
Toshi MARUYAMA 2011-08-20 06:50:09 +00:00
parent 2ea231b9e6
commit 75ce76cd74

View File

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