1 # redMine - project management software
2 # Copyright (C) 2006 Jean-Philippe Lang
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 module RepositoriesHelper
21 def format_revision(txt)
25 def truncate_at_line_break(text, length = 255)
27 text.gsub(%r{^(.{#{length}}[^\n]*)\n.+$}m, '\\1...')
31 def render_properties(properties)
32 unless properties.nil? || properties.empty?
34 properties.keys.sort.each do |property|
35 content << content_tag('li', "<b>#{h property}</b>: <span>#{h properties[property]}</span>")
37 content_tag('ul', content, :class => 'properties')
41 def render_changeset_changes
42 changes = @changeset.changes.find(:all, :limit => 1000, :order => 'path').collect do |change|
45 # Detects moved/copied files
46 if !change.from_path.blank?
47 change.action = @changeset.changes.detect {|c| c.action == 'D' && c.path == change.from_path} ? 'R' : 'C'
51 @changeset.changes.detect {|c| c.from_path == change.path} ? nil : change
58 changes.each do |change|
60 dirs = change.path.to_s.split('/').select {|d| !d.blank?}
70 render_changes_tree(tree[:s])
73 def render_changes_tree(tree)
74 return '' if tree.nil?
78 tree.keys.sort.each do |file|
79 s = !tree[file][:s].nil?
83 style << ' folder' if s
84 style << " change-#{c.action}" if c
88 path_param = to_path_param(@repository.relative_path(c.path))
89 text = link_to(text, :controller => 'repositories',
93 :rev => @changeset.revision) unless s || c.action == 'D'
94 text << " - #{c.revision}" unless c.revision.blank?
95 text << ' (' + link_to('diff', :controller => 'repositories',
99 :rev => @changeset.revision) + ') ' if c.action == 'M'
100 text << ' ' + content_tag('span', c.from_path, :class => 'copied-from') unless c.from_path.blank?
102 output << "<li class='#{style}'>#{text}</li>"
103 output << render_changes_tree(tree[file][:s]) if s
110 return str if /\A[\r\n\t\x20-\x7e]*\Z/n.match(str) # for us-ascii
111 @encodings ||= Setting.repositories_encodings.split(',').collect(&:strip)
112 @encodings.each do |encoding|
114 return Iconv.conv('UTF-8', encoding, str)
115 rescue Iconv::Failure
116 # do nothing here and try the next encoding
122 def repository_field_tags(form, repository)
123 method = repository.class.name.demodulize.underscore + "_field_tags"
124 send(method, form, repository) if repository.is_a?(Repository) && respond_to?(method) && method != 'repository_field_tags'
127 def scm_select_tag(repository)
128 scm_options = [["--- #{l(:actionview_instancetag_blank_option)} ---", '']]
129 Redmine::Scm::Base.all.each do |scm|
130 scm_options << ["Repository::#{scm}".constantize.scm_name, scm] if Setting.enabled_scm.include?(scm) || (repository && repository.class.name.demodulize == scm)
133 select_tag('repository_scm',
134 options_for_select(scm_options, repository.class.name.demodulize),
135 :disabled => (repository && !repository.new_record?),
136 :onchange => remote_function(:url => { :controller => 'repositories', :action => 'edit', :id => @project }, :method => :get, :with => "Form.serialize(this.form)")
140 def with_leading_slash(path)
141 path.to_s.starts_with?('/') ? path : "/#{path}"
144 def without_leading_slash(path)
145 path.gsub(%r{^/+}, '')
148 def subversion_field_tags(form, repository)
149 content_tag('p', form.text_field(:url, :size => 60, :required => true, :disabled => (repository && !repository.root_url.blank?)) +
150 '<br />(file:///, http://, https://, svn://, svn+[tunnelscheme]://)') +
151 content_tag('p', form.text_field(:login, :size => 30)) +
152 content_tag('p', form.password_field(:password, :size => 30, :name => 'ignore',
153 :value => ((repository.new_record? || repository.password.blank?) ? '' : ('x'*15)),
154 :onfocus => "this.value=''; this.name='repository[password]';",
155 :onchange => "this.name='repository[password]';"))
158 def darcs_field_tags(form, repository)
159 content_tag('p', form.text_field(:url, :label => 'Root directory', :size => 60, :required => true, :disabled => (repository && !repository.new_record?)))
162 def mercurial_field_tags(form, repository)
163 content_tag('p', form.text_field(:url, :label => 'Root directory', :size => 60, :required => true, :disabled => (repository && !repository.root_url.blank?)))
166 def git_field_tags(form, repository)
167 content_tag('p', form.text_field(:url, :label => 'Path to .git directory', :size => 60, :required => true, :disabled => (repository && !repository.root_url.blank?)))
170 def cvs_field_tags(form, repository)
171 content_tag('p', form.text_field(:root_url, :label => 'CVSROOT', :size => 60, :required => true, :disabled => !repository.new_record?)) +
172 content_tag('p', form.text_field(:url, :label => 'Module', :size => 30, :required => true, :disabled => !repository.new_record?))
175 def bazaar_field_tags(form, repository)
176 content_tag('p', form.text_field(:url, :label => 'Root directory', :size => 60, :required => true, :disabled => (repository && !repository.new_record?)))
179 def filesystem_field_tags(form, repository)
180 content_tag('p', form.text_field(:url, :label => 'Root directory', :size => 60, :required => true, :disabled => (repository && !repository.root_url.blank?)))