comparison vendor/plugins/redmine_checkout/init.rb @ 16:020926a36823 yuya

* Add redmine-checkout plugin (as of svn rev 179 of the plugin)
author Chris Cannam
date Wed, 25 Aug 2010 16:39:01 +0100
parents
children
comparison
equal deleted inserted replaced
15:9c6c72729d91 16:020926a36823
1 require 'redmine'
2
3 require 'dispatcher'
4 Dispatcher.to_prepare do
5 # Patches
6 require_dependency 'checkout/settings_controller_patch'
7
8 require_dependency 'checkout/repositories_helper_patch'
9 require_dependency 'checkout/repository_patch'
10
11 require_dependency 'checkout/settings_helper_patch'
12 require_dependency 'checkout/setting_patch'
13 end
14
15 # Hooks
16 require 'checkout/repository_hooks'
17
18 Redmine::Plugin.register :redmine_checkout do
19 name 'Redmine Checkout plugin'
20 url 'http://dev.holgerjust.de/projects/redmine-checkout'
21 author 'Holger Just'
22 author_url 'http://meine-er.de'
23 description 'Add links to the actual repository to the repository view.'
24 version '0.5'
25
26 requires_redmine :version_or_higher => '0.9'
27
28 settings_defaults = HashWithIndifferentAccess.new({
29 'display_login' => nil,
30 'use_zero_clipboard' => '1',
31
32 'display_checkout_info' => '1',
33 'description_Abstract' => <<-EOF
34 The data contained in this repository can be downloaded to your computer using one of several clients.
35 Please see the documentation of your version control software client for more information.
36
37 Please select the desired protocol below to get the URL.
38 EOF
39 })
40
41 # this is needed for setting the defaults
42 require 'checkout/repository_patch'
43
44 CheckoutHelper.supported_scm.each do |scm|
45 klazz = "Repository::#{scm}".constantize
46
47 settings_defaults["description_#{scm}"] = ''
48 settings_defaults["overwrite_description_#{scm}"] = '0'
49 settings_defaults["display_command_#{scm}"] = '0'
50
51 # access can be one of
52 # read+write => this protocol always allows read/write access
53 # read-only => this protocol always allows read access only
54 # permission => Access depends on redmine permissions
55 settings_defaults["protocols_#{scm}"] = [HashWithIndifferentAccess.new({
56 :protocol => scm,
57 :command => klazz.checkout_default_command,
58 :regex => '',
59 :regex_replacement => '',
60 :fixed_url => '',
61 :access => 'permission',
62 :append_path => (klazz.allow_subtree_checkout? ? '1' : '0'),
63 :is_default => '1'
64 })]
65 end
66
67 settings :default => settings_defaults, :partial => 'settings/redmine_checkout'
68
69 Redmine::WikiFormatting::Macros.register do
70 desc <<-EOF
71 Creates a checkout link to the actual repository. Example:
72
73 use the default checkout protocol !{{repository}}
74 or use a specific protocol !{{repository(SVN)}}
75 or use the checkout protocol of a specific specific project: !{{repository(projectname:SVN)}}"
76 EOF
77
78 macro :repository do |obj, args|
79 proto = args.first
80 if proto.to_s =~ %r{^([^\:]+)\:(.*)$}
81 project_identifier, proto = $1, $2
82 project = Project.find_by_identifier(project_identifier) || Project.find_by_name(project_identifier)
83 else
84 project = @project
85 end
86
87 if project && project.repository
88 protocols = project.repository.checkout_protocols.select{|p| p.access_rw(User.current)}
89
90 if proto.present?
91 proto_obj = protocols.find{|p| p.protocol.downcase == proto.downcase}
92 else
93 proto_obj = protocols.find(&:default?) || protocols.first
94 end
95 end
96 raise "Checkout protocol #{proto} not found" unless proto_obj
97
98 cmd = (project.repository.checkout_display_command? && proto_obj.command.present?) ? proto_obj.command.strip + " " : ""
99 cmd + link_to(proto_obj.url, proto_obj.url)
100 end
101 end
102 end