You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

repositories_helper.rb 4.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. # redMine - project management software
  2. # Copyright (C) 2006 Jean-Philippe Lang
  3. #
  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.
  8. #
  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.
  13. #
  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.
  17. require 'coderay'
  18. require 'coderay/helpers/file_type'
  19. require 'iconv'
  20. module RepositoriesHelper
  21. def syntax_highlight(name, content)
  22. type = CodeRay::FileType[name]
  23. type ? CodeRay.scan(content, type).html : h(content)
  24. end
  25. def format_revision(txt)
  26. txt.to_s[0,8]
  27. end
  28. def to_utf8(str)
  29. return str if /\A[\r\n\t\x20-\x7e]*\Z/n.match(str) # for us-ascii
  30. @encodings ||= Setting.repositories_encodings.split(',').collect(&:strip)
  31. @encodings.each do |encoding|
  32. begin
  33. return Iconv.conv('UTF-8', encoding, str)
  34. rescue Iconv::Failure
  35. # do nothing here and try the next encoding
  36. end
  37. end
  38. str
  39. end
  40. def repository_field_tags(form, repository)
  41. method = repository.class.name.demodulize.underscore + "_field_tags"
  42. send(method, form, repository) if repository.is_a?(Repository) && respond_to?(method)
  43. end
  44. def scm_select_tag(repository)
  45. container = [[]]
  46. REDMINE_SUPPORTED_SCM.each {|scm| container << ["Repository::#{scm}".constantize.scm_name, scm]}
  47. select_tag('repository_scm',
  48. options_for_select(container, repository.class.name.demodulize),
  49. :disabled => (repository && !repository.new_record?),
  50. :onchange => remote_function(:url => { :controller => 'repositories', :action => 'edit', :id => @project }, :method => :get, :with => "Form.serialize(this.form)")
  51. )
  52. end
  53. def with_leading_slash(path)
  54. path.to_s.starts_with?('/') ? path : "/#{path}"
  55. end
  56. def without_leading_slash(path)
  57. path.gsub(%r{^/+}, '')
  58. end
  59. def subversion_field_tags(form, repository)
  60. content_tag('p', form.text_field(:url, :size => 60, :required => true, :disabled => (repository && !repository.root_url.blank?)) +
  61. '<br />(http://, https://, svn://, file:///)') +
  62. content_tag('p', form.text_field(:login, :size => 30)) +
  63. content_tag('p', form.password_field(:password, :size => 30, :name => 'ignore',
  64. :value => ((repository.new_record? || repository.password.blank?) ? '' : ('x'*15)),
  65. :onfocus => "this.value=''; this.name='repository[password]';",
  66. :onchange => "this.name='repository[password]';"))
  67. end
  68. def darcs_field_tags(form, repository)
  69. content_tag('p', form.text_field(:url, :label => 'Root directory', :size => 60, :required => true, :disabled => (repository && !repository.new_record?)))
  70. end
  71. def mercurial_field_tags(form, repository)
  72. content_tag('p', form.text_field(:url, :label => 'Root directory', :size => 60, :required => true, :disabled => (repository && !repository.root_url.blank?)))
  73. end
  74. def git_field_tags(form, repository)
  75. content_tag('p', form.text_field(:url, :label => 'Path to .git directory', :size => 60, :required => true, :disabled => (repository && !repository.root_url.blank?)))
  76. end
  77. def cvs_field_tags(form, repository)
  78. content_tag('p', form.text_field(:root_url, :label => 'CVSROOT', :size => 60, :required => true, :disabled => !repository.new_record?)) +
  79. content_tag('p', form.text_field(:url, :label => 'Module', :size => 30, :required => true, :disabled => !repository.new_record?))
  80. end
  81. def bazaar_field_tags(form, repository)
  82. content_tag('p', form.text_field(:url, :label => 'Root directory', :size => 60, :required => true, :disabled => (repository && !repository.new_record?)))
  83. end
  84. end