This repository has been archived by the owner on Dec 7, 2024. It is now read-only.
forked from maxrossello/redmine_glossary
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinit.rb
79 lines (66 loc) · 2.5 KB
/
init.rb
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
78
79
require 'redmine'
require 'cgi'
require 'glossary_asset_tag_helper_patch'
require 'term_link_helper'
require_dependency 'glossary_view_layouts_base_html_head_hook'
ActionView::Base.class_eval do
include ActionView::Helpers::TermLinkHelper
end
Redmine::Plugin.register :redmine_glossary do
name 'Redmine Glossary Plugin'
author 'M. Yoshida'
description "This is a Redmine plugin to create a glossary which is is a list of terms in a project"
version '0.7.0'
author_url 'http://yohshiy.blog.fc2.com/'
url 'http://www.r-labs.org/projects/rp-glossary/wiki/GlossaryEn'
requires_redmine :version_or_higher => '2.3'
settings :default => {
'hide_item_term_en' => false,
'hide_item_codename' => false,
'hide_item_datatype' => false,
'hide_item_rubi' => false,
'hide_item_abbr_whole' => false,
}, :partial => 'settings/glossary_settings'
project_module :glossary do
permission(:view_terms, {:glossary => [:index, :index_clear, :show, :show_all]})
permission(:manage_terms, {:glossary => [:new, :edit, :destroy, :preview,
:import_csv, :import_csv_exec, :move_all]},
:require => :member)
permission(:manage_term_categories,
{:glossary => [:add_term_category, :move_all],
:term_categories => [:index, :change_order, :edit, :destroy]},
:require => :member)
end
menu(:project_menu, :glossary,
{ :controller => 'glossary', :action => 'index' },
:caption => :glossary_title, :param => :project_id)
end
Redmine::WikiFormatting::Macros.register do
desc "Glossary term link by ID"
macro :termno do |obj, args|
raise I18n.t(:error_termno_macro_arg) if (args.size != 1)
tid = args[0].strip
term = Term.find_by_id(tid.to_i)
raise sprintf(I18n.t(:error_term_not_found_id), tid) unless term
term_link(term)
end
end
Redmine::WikiFormatting::Macros.register do
desc "Glossary term link"
macro :term do |obj, args|
sargs = args.map {|arg| CGI::unescapeHTML(arg.strip) }
term = nil
case sargs.size
when 1
proj = Project.find_by_identifier(params[:project_id]) unless proj
term = Term.find_for_macro(sargs[0], proj, true)
when 2
proj = Project.find_by_identifier(sargs[1])
raise sprintf(I18n.t(:error_project_not_found), sargs[1]) unless proj
term = Term.find_for_macro(sargs[0], proj)
else
raise I18n.t(:error_term_macro_arg)
end
(term) ? term_link(term) : term_link_new(sargs[0], proj)
end
end