root / init.rb
History | View | Annotate | Download (2.9 KB)
1 |
require 'redmine'
|
---|---|
2 |
|
3 |
require_dependency 'download_hook'
|
4 |
|
5 |
Rails.logger.info 'Starting Download Plugin for Redmine' |
6 |
|
7 |
Rails.configuration.to_prepare do |
8 |
unless ActionView::Base.included_modules.include?(DownloadHelper) |
9 |
ActionView::Base.send(:include, DownloadHelper) |
10 |
end
|
11 |
unless VersionsController.included_modules.include?(DownloadVersionsControllerPatch) |
12 |
VersionsController.send(:include, DownloadVersionsControllerPatch) |
13 |
end
|
14 |
begin
|
15 |
unless FilesController.included_modules.include?(DownloadFilesControllerPatch) |
16 |
FilesController.send(:include, DownloadFilesControllerPatch) |
17 |
end
|
18 |
rescue NameError |
19 |
unless ProjectsController.included_modules.include?(DownloadProjectsControllerPatch) |
20 |
ProjectsController.send(:include, DownloadProjectsControllerPatch) |
21 |
end
|
22 |
end
|
23 |
unless AttachmentsController.included_modules.include?(DownloadAttachmentsControllerPatch) |
24 |
AttachmentsController.send(:include, DownloadAttachmentsControllerPatch) |
25 |
end
|
26 |
unless ProjectsHelper.included_modules.include?(DownloadProjectsHelperPatch) |
27 |
ProjectsHelper.send(:include, DownloadProjectsHelperPatch) |
28 |
end
|
29 |
|
30 |
if defined? ChiliProject::Liquid::Tags |
31 |
require_dependency 'chiliproject/liquid/tags/download'
|
32 |
|
33 |
ChiliProject::Liquid::Tags.register_tag('download', Download, :html => true) |
34 |
end
|
35 |
end
|
36 |
|
37 |
Redmine::Plugin.register :download do |
38 |
name 'Download button'
|
39 |
author 'Andriy Lesyuk'
|
40 |
author_url 'http://www.andriylesyuk.com/'
|
41 |
description 'Adds Download button to projects.'
|
42 |
url 'http://projects.andriylesyuk.com/projects/download-button'
|
43 |
version '0.1.1'
|
44 |
|
45 |
permission :manage_download_button, { :projects => :settings, :download => :edit }, :require => :member |
46 |
end
|
47 |
|
48 |
unless defined? ChiliProject::Liquid::Tags |
49 |
|
50 |
Redmine::WikiFormatting::Macros.register do |
51 |
desc "Inserts Download button in Wiki page."
|
52 |
macro :download do |page, args| |
53 |
button = ''
|
54 |
|
55 |
options = {} |
56 |
args.each do |arg|
|
57 |
if arg =~ %r{^([^=]+)\=(.*)$} |
58 |
options[$1.downcase.to_sym] = $2 |
59 |
end
|
60 |
end
|
61 |
|
62 |
if options[:project] |
63 |
project = Project.find_by_identifier(options[:project]) |
64 |
elsif page.respond_to?(:project) |
65 |
project = page.project |
66 |
end
|
67 |
|
68 |
if project && project.versions.any?
|
69 |
download = DownloadButton.from_options(project, options)
|
70 |
if download && !download.disabled?
|
71 |
latest_version = latest_version(project) |
72 |
if latest_version && download.version && latest_version.id != download.version.id
|
73 |
options.merge!(:class => 'old-version') |
74 |
end
|
75 |
button = download_button(project, download, options) |
76 |
end
|
77 |
end
|
78 |
|
79 |
button |
80 |
end
|
81 |
end
|
82 |
|
83 |
end
|