2006-12-24 16:38:45 +03:00
|
|
|
# redMine - project management software
|
|
|
|
# Copyright (C) 2006 Jean-Philippe Lang
|
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or
|
|
|
|
# modify it under the terms of the GNU General Public License
|
|
|
|
# as published by the Free Software Foundation; either version 2
|
|
|
|
# of the License, or (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program; if not, write to the Free Software
|
|
|
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
2007-08-16 00:20:18 +04:00
|
|
|
require 'coderay'
|
|
|
|
require 'coderay/helpers/file_type'
|
2007-10-07 19:21:40 +04:00
|
|
|
require 'iconv'
|
2007-08-16 00:20:18 +04:00
|
|
|
|
2006-12-24 16:38:45 +03:00
|
|
|
module RepositoriesHelper
|
2007-08-16 00:20:18 +04:00
|
|
|
def syntax_highlight(name, content)
|
|
|
|
type = CodeRay::FileType[name]
|
|
|
|
type ? CodeRay.scan(content, type).html : h(content)
|
|
|
|
end
|
2007-10-07 19:21:40 +04:00
|
|
|
|
2008-03-12 23:28:49 +03:00
|
|
|
def format_revision(txt)
|
|
|
|
txt.to_s[0,8]
|
|
|
|
end
|
|
|
|
|
2007-10-07 19:21:40 +04:00
|
|
|
def to_utf8(str)
|
|
|
|
return str if /\A[\r\n\t\x20-\x7e]*\Z/n.match(str) # for us-ascii
|
|
|
|
@encodings ||= Setting.repositories_encodings.split(',').collect(&:strip)
|
|
|
|
@encodings.each do |encoding|
|
|
|
|
begin
|
|
|
|
return Iconv.conv('UTF-8', encoding, str)
|
|
|
|
rescue Iconv::Failure
|
|
|
|
# do nothing here and try the next encoding
|
|
|
|
end
|
|
|
|
end
|
|
|
|
str
|
|
|
|
end
|
|
|
|
|
2007-06-13 00:12:05 +04:00
|
|
|
def repository_field_tags(form, repository)
|
|
|
|
method = repository.class.name.demodulize.underscore + "_field_tags"
|
|
|
|
send(method, form, repository) if repository.is_a?(Repository) && respond_to?(method)
|
|
|
|
end
|
|
|
|
|
2007-09-14 15:34:08 +04:00
|
|
|
def scm_select_tag(repository)
|
2007-06-13 00:12:05 +04:00
|
|
|
container = [[]]
|
|
|
|
REDMINE_SUPPORTED_SCM.each {|scm| container << ["Repository::#{scm}".constantize.scm_name, scm]}
|
|
|
|
select_tag('repository_scm',
|
2007-09-14 15:34:08 +04:00
|
|
|
options_for_select(container, repository.class.name.demodulize),
|
|
|
|
:disabled => (repository && !repository.new_record?),
|
|
|
|
:onchange => remote_function(:url => { :controller => 'repositories', :action => 'edit', :id => @project }, :method => :get, :with => "Form.serialize(this.form)")
|
2007-06-13 00:12:05 +04:00
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
def with_leading_slash(path)
|
2008-04-04 02:29:58 +04:00
|
|
|
path.to_s.starts_with?('/') ? path : "/#{path}"
|
|
|
|
end
|
|
|
|
|
|
|
|
def without_leading_slash(path)
|
|
|
|
path.gsub(%r{^/+}, '')
|
2007-06-13 00:12:05 +04:00
|
|
|
end
|
|
|
|
|
|
|
|
def subversion_field_tags(form, repository)
|
|
|
|
content_tag('p', form.text_field(:url, :size => 60, :required => true, :disabled => (repository && !repository.root_url.blank?)) +
|
|
|
|
'<br />(http://, https://, svn://, file:///)') +
|
|
|
|
content_tag('p', form.text_field(:login, :size => 30)) +
|
2007-12-02 01:03:45 +03:00
|
|
|
content_tag('p', form.password_field(:password, :size => 30, :name => 'ignore',
|
|
|
|
:value => ((repository.new_record? || repository.password.blank?) ? '' : ('x'*15)),
|
|
|
|
:onfocus => "this.value=''; this.name='repository[password]';",
|
|
|
|
:onchange => "this.name='repository[password]';"))
|
2007-06-13 00:12:05 +04:00
|
|
|
end
|
|
|
|
|
2007-06-24 23:30:38 +04:00
|
|
|
def darcs_field_tags(form, repository)
|
|
|
|
content_tag('p', form.text_field(:url, :label => 'Root directory', :size => 60, :required => true, :disabled => (repository && !repository.new_record?)))
|
|
|
|
end
|
|
|
|
|
2007-06-13 00:12:05 +04:00
|
|
|
def mercurial_field_tags(form, repository)
|
|
|
|
content_tag('p', form.text_field(:url, :label => 'Root directory', :size => 60, :required => true, :disabled => (repository && !repository.root_url.blank?)))
|
|
|
|
end
|
|
|
|
|
2008-03-12 23:28:49 +03:00
|
|
|
def git_field_tags(form, repository)
|
|
|
|
content_tag('p', form.text_field(:url, :label => 'Path to .git directory', :size => 60, :required => true, :disabled => (repository && !repository.root_url.blank?)))
|
|
|
|
end
|
|
|
|
|
2007-06-13 00:12:05 +04:00
|
|
|
def cvs_field_tags(form, repository)
|
|
|
|
content_tag('p', form.text_field(:root_url, :label => 'CVSROOT', :size => 60, :required => true, :disabled => !repository.new_record?)) +
|
|
|
|
content_tag('p', form.text_field(:url, :label => 'Module', :size => 30, :required => true, :disabled => !repository.new_record?))
|
|
|
|
end
|
2007-12-03 20:40:43 +03:00
|
|
|
|
|
|
|
def bazaar_field_tags(form, repository)
|
|
|
|
content_tag('p', form.text_field(:url, :label => 'Root directory', :size => 60, :required => true, :disabled => (repository && !repository.new_record?)))
|
|
|
|
end
|
2006-12-24 16:38:45 +03:00
|
|
|
end
|