Module: RepositoriesHelper
- Included in:
- IssuesController, ProjectsController
- Defined in:
- app/helpers/repositories_helper.rb
Instance Method Summary collapse
- #bazaar_field_tags(form, repository) ⇒ Object
- #cvs_field_tags(form, repository) ⇒ Object
- #darcs_field_tags(form, repository) ⇒ Object
- #filesystem_field_tags(form, repository) ⇒ Object
- #format_revision(revision) ⇒ Object
- #git_field_tags(form, repository) ⇒ Object
- #mercurial_field_tags(form, repository) ⇒ Object
- #render_changes_tree(tree) ⇒ Object
- #render_changeset_changes ⇒ Object
- #render_properties(properties) ⇒ Object
- #replace_invalid_utf8(str) ⇒ Object
- #repository_field_tags(form, repository) ⇒ Object
- #scm_select_tag(repository) ⇒ Object
- #subversion_field_tags(form, repository) ⇒ Object
- #to_utf8(str) ⇒ Object
- #truncate_at_line_break(text, length = 255) ⇒ Object
- #with_leading_slash(path) ⇒ Object
- #without_leading_slash(path) ⇒ Object
Instance Method Details
#bazaar_field_tags(form, repository) ⇒ Object
260 261 262 263 264 265 266 |
# File 'app/helpers/repositories_helper.rb', line 260 def (form, repository) content_tag('p', form.text_field(:url, :label => 'Root directory', :size => 60, :required => true, :disabled => (repository && !repository.new_record?))) + content_tag('p', form.select(:log_encoding, [nil] + Setting::ENCODINGS, :label => 'Commit messages encoding', :required => true)) end |
#cvs_field_tags(form, repository) ⇒ Object
249 250 251 252 253 254 255 256 257 258 |
# File 'app/helpers/repositories_helper.rb', line 249 def (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?)) + content_tag('p', form.select(:log_encoding, [nil] + Setting::ENCODINGS, :label => 'Commit messages encoding', :required => true)) end |
#darcs_field_tags(form, repository) ⇒ Object
219 220 221 222 223 224 225 |
# File 'app/helpers/repositories_helper.rb', line 219 def (form, repository) content_tag('p', form.text_field(:url, :label => 'Root directory', :size => 60, :required => true, :disabled => (repository && !repository.new_record?))) + content_tag('p', form.select(:log_encoding, [nil] + Setting::ENCODINGS, :label => 'Commit messages encoding', :required => true)) end |
#filesystem_field_tags(form, repository) ⇒ Object
268 269 270 271 272 273 274 275 276 |
# File 'app/helpers/repositories_helper.rb', line 268 def (form, repository) content_tag('p', form.text_field(:url, :label => 'Root directory', :size => 60, :required => true, :disabled => (repository && !repository.root_url.blank?))) + content_tag('p', form.select( :path_encoding, [nil] + Setting::ENCODINGS, :label => 'Path encoding') + '<br />Default: UTF-8') end |
#format_revision(revision) ⇒ Object
21 22 23 24 25 26 27 |
# File 'app/helpers/repositories_helper.rb', line 21 def format_revision(revision) if revision.respond_to? :format_identifier revision.format_identifier else revision.to_s end end |
#git_field_tags(form, repository) ⇒ Object
238 239 240 241 242 243 244 245 246 247 |
# File 'app/helpers/repositories_helper.rb', line 238 def (form, repository) content_tag('p', form.text_field(:url, :label => 'Path to repository', :size => 60, :required => true, :disabled => (repository && !repository.root_url.blank?)) + '<br />Bare and local repository (e.g. /gitrepo, c:\gitrepo)') + content_tag('p', form.select( :path_encoding, [nil] + Setting::ENCODINGS, :label => 'Path encoding') + '<br />Default: UTF-8') end |
#mercurial_field_tags(form, repository) ⇒ Object
227 228 229 230 231 232 233 234 235 236 |
# File 'app/helpers/repositories_helper.rb', line 227 def (form, repository) content_tag('p', form.text_field(:url, :label => 'Root directory', :size => 60, :required => true, :disabled => (repository && !repository.root_url.blank?)) + '<br />Local repository (e.g. /hgrepo, c:\hgrepo)' ) + content_tag('p', form.select( :path_encoding, [nil] + Setting::ENCODINGS, :label => 'Path encoding') + '<br />Default: UTF-8') end |
#render_changes_tree(tree) ⇒ Object
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'app/helpers/repositories_helper.rb', line 79 def render_changes_tree(tree) return '' if tree.nil? output = '' output << '<ul>' tree.keys.sort.each do |file| style = 'change' text = File.basename(h(file)) if s = tree[file][:s] style << ' folder' path_param = to_path_param(@repository.relative_path(file)) text = link_to(text, :controller => 'repositories', :action => 'show', :id => @project, :path => path_param, :rev => @changeset.identifier) output << "<li class='#{style}'>#{text}</li>" output << render_changes_tree(s) elsif c = tree[file][:c] style << " change-#{c.action}" path_param = to_path_param(@repository.relative_path(c.path)) text = link_to(text, :controller => 'repositories', :action => 'entry', :id => @project, :path => path_param, :rev => @changeset.identifier) unless c.action == 'D' text << " - #{c.revision}" unless c.revision.blank? text << ' (' + link_to('diff', :controller => 'repositories', :action => 'diff', :id => @project, :path => path_param, :rev => @changeset.identifier) + ') ' if c.action == 'M' text << ' ' + content_tag('span', c.from_path, :class => 'copied-from') unless c.from_path.blank? output << "<li class='#{style}'>#{text}</li>" end end output << '</ul>' output end |
#render_changeset_changes ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'app/helpers/repositories_helper.rb', line 45 def render_changeset_changes changes = @changeset.changes.find(:all, :limit => 1000, :order => 'path').collect do |change| case change.action when 'A' # Detects moved/copied files if !change.from_path.blank? change.action = @changeset.changes.detect {|c| c.action == 'D' && c.path == change.from_path} ? 'R' : 'C' end change when 'D' @changeset.changes.detect {|c| c.from_path == change.path} ? nil : change else change end end.compact tree = { } changes.each do |change| p = tree dirs = change.path.to_s.split('/').select {|d| !d.blank?} path = '' dirs.each do |dir| path += '/' + dir p[:s] ||= {} p = p[:s] p[path] ||= {} p = p[path] end p[:c] = change end render_changes_tree(tree[:s]) end |
#render_properties(properties) ⇒ Object
35 36 37 38 39 40 41 42 43 |
# File 'app/helpers/repositories_helper.rb', line 35 def render_properties(properties) unless properties.nil? || properties.empty? content = '' properties.keys.sort.each do |property| content << content_tag('li', "<b>#{h property}</b>: <span>#{h properties[property]}</span>") end content_tag('ul', content, :class => 'properties') end end |
#replace_invalid_utf8(str) ⇒ Object
150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 |
# File 'app/helpers/repositories_helper.rb', line 150 def replace_invalid_utf8(str) return str if str.nil? if str.respond_to?(:force_encoding) str.force_encoding('UTF-8') if ! str.valid_encoding? str = str.encode("US-ASCII", :invalid => :replace, :undef => :replace, :replace => '?').encode("UTF-8") end else # removes invalid UTF8 sequences begin str = Iconv.conv('UTF-8//IGNORE', 'UTF-8', str + ' ')[0..-3] rescue Iconv::InvalidEncoding # "UTF-8//IGNORE" is not supported on some OS end end str end |
#repository_field_tags(form, repository) ⇒ Object
169 170 171 172 173 174 175 |
# File 'app/helpers/repositories_helper.rb', line 169 def (form, repository) method = repository.class.name.demodulize.underscore + "_field_tags" if repository.is_a?(Repository) && respond_to?(method) && method != 'repository_field_tags' send(method, form, repository) end end |
#scm_select_tag(repository) ⇒ Object
177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 |
# File 'app/helpers/repositories_helper.rb', line 177 def scm_select_tag(repository) = [["--- #{l(:actionview_instancetag_blank_option)} ---", '']] Redmine::Scm::Base.all.each do |scm| if Setting.enabled_scm.include?(scm) || (repository && repository.class.name.demodulize == scm) << ["Repository::#{scm}".constantize.scm_name, scm] end end select_tag('repository_scm', (, 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)") ) end |
#subversion_field_tags(form, repository) ⇒ Object
207 208 209 210 211 212 213 214 215 216 217 |
# File 'app/helpers/repositories_helper.rb', line 207 def (form, repository) content_tag('p', form.text_field(:url, :size => 60, :required => true, :disabled => (repository && !repository.root_url.blank?)) + '<br />(file:///, http://, https://, svn://, svn+[tunnelscheme]://)') + content_tag('p', form.text_field(:login, :size => 30)) + 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]';")) end |
#to_utf8(str) ⇒ Object
119 120 121 122 123 124 125 126 |
# File 'app/helpers/repositories_helper.rb', line 119 def to_utf8(str) return str if str.nil? str = to_utf8_internal(str) if str.respond_to?(:force_encoding) str.force_encoding('UTF-8') end str end |
#truncate_at_line_break(text, length = 255) ⇒ Object
29 30 31 32 33 |
# File 'app/helpers/repositories_helper.rb', line 29 def truncate_at_line_break(text, length = 255) if text text.gsub(%r{^(.{#{length}}[^\n]*)\n.+$}m, '\\1...') end end |
#with_leading_slash(path) ⇒ Object
199 200 201 |
# File 'app/helpers/repositories_helper.rb', line 199 def with_leading_slash(path) path.to_s.starts_with?('/') ? path : "/#{path}" end |
#without_leading_slash(path) ⇒ Object
203 204 205 |
# File 'app/helpers/repositories_helper.rb', line 203 def without_leading_slash(path) path.gsub(%r{^/+}, '') end |