public
Description: Add a named tab to Redmine that links to an iframe
Homepage:
Clone URL: git://github.com/jamtur01/redmine_tab.git
redmine_tab / init.rb
100644 77 lines (64 sloc) 2.648 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# Redmine - project management software
# Copyright (C) 2006-2009 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.
 
require 'redmine'
 
RAILS_DEFAULT_LOGGER.info 'Tab'
 
Redmine::Plugin.register :redmine_tab do
  name 'Tab Plugin'
  author 'James Turnbull'
  description 'A plugin to allow users to add a new tab with a link to an iframe.'
  version '0.3.0'
  
  settings :default => {
    'tab_text' => '',
    'tab_name' => 'Tab Name',
    'system_tab_text' => '',
    'system_tab_name' => 'System Tab Name'
 
  }, :partial => 'settings/redminetab_settings'
 
  # This plugin adds a project module
  # It can be enabled/disabled at project level (Project settings -> Modules)
  project_module :tab do
    # This permission has to be explicitly given
    # It will be listed on the permissions screen
    permission :view_tab, {:tab => :show}
  end
 
  # Translate or return the setting_name directly
  string_or_translate = lambda {|setting_name|
    string = Setting.plugin_redmine_tab[setting_name]
    if !string.blank? && string.match(/\A:/) # uses symbol syntax, :string
      string.gsub!(':','')
      string = GLoc.l(string.to_sym) if Object.const_defined?('GLoc') # Rails 2.1.x
      string = I18n.t(string.to_sym) if Object.const_defined?('I18n') # Rails 2.2.x
    end
    string
  }
  
  # A new item is added to the project menu
  menu(:project_menu,
       :tab,
       { :controller => 'tab', :action => 'show' },
       :caption => Proc.new { string_or_translate.call('tab_name') },
       :if => Proc.new { !Setting.plugin_redmine_tab['tab_name'].blank? })
 
  
  menu(:top_menu,
       :tab,
       { :controller => 'tab', :action => 'system_show' },
       :caption => Proc.new { string_or_translate.call('system_tab_name') },
       :if => Proc.new { !Setting.plugin_redmine_tab['system_tab_name'].blank? })
end
 
Rails::Plugin.class_eval do
   def reloadable!
     load_paths.each { |p| Dependencies.load_once_paths.delete(p) }
   end
end
 
reloadable!