annotate vendor/plugins/redmine_checkout/init.rb @ 861:b8105f717bf7 bug_182

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