init.rb

Yuki Kita, 2010-04-06 01:58

Download (1.03 KB)

 
1
require 'redmine'
2

    
3
RAILS_DEFAULT_LOGGER.info 'Menu Link plugin 0.0.1 for Redmine'
4

    
5
Redmine::Plugin.register :menu_link do
6
  name 'Menu Link Plugin'
7
  author 'Tide, Yuki Kita'
8
  description 'A plugin which adds a link to the top menu of Redmine.'
9
  version '0.0.1'
10

    
11
  settings :default => {
12
    'link_item_text' => 'http://www.google.com',
13
    'link_item_name' => 'Google',
14
    'new_window' => '0'
15

    
16
  }, :partial => 'settings/menulink_settings'
17
  menu(:top_menu,
18
      :link,
19
      Proc.new { Setting.plugin_menu_link['link_item_text'] },
20
      :caption => Proc.new { Setting.plugin_menu_link['link_item_name'] })
21
end
22

    
23
class MenuListener < Redmine::Hook::ViewListener
24
  def view_layouts_base_html_head(context)
25
    if Setting.plugin_menu_link['new_window'] == "0"
26
      Redmine::MenuManager.map(:top_menu).find(:link).html_options[:target] = nil
27
    else
28
      Redmine::MenuManager.map(:top_menu).find(:link).html_options[:target] = '_blank'
29
    end
30
    nil
31
  end
32
end
33

    
34
menu = Redmine::MenuManager.map(:top_menu).find(:link)
35
def menu.url
36
  @url.call
37
end