##// END OF EJS Templates
Add Redmine links for repository files using source: and export: keyworkds (#867)....
Jean-Philippe Lang -
r1252:93d1b2e0a439
parent child
Show More
@@ -97,7 +97,8 class RepositoriesController < ApplicationController
97 97 def entry
98 98 @content = @repository.scm.cat(@path, @rev)
99 99 show_error_not_found and return unless @content
100 if 'raw' == params[:format]
100 if 'raw' == params[:format] || @content.is_binary_data?
101 # Force the download if it's a binary file
101 102 send_data @content, :filename => @path.split('/').last
102 103 else
103 104 # Prevent empty lines when displaying a file with Windows style eol
@@ -281,13 +281,19 module ApplicationHelper
281 281 # version:"1.0 beta 2" -> Link to version named "1.0 beta 2"
282 282 # Attachments:
283 283 # attachment:file.zip -> Link to the attachment of the current object named file.zip
284 text = text.gsub(%r{([\s\(,-^])(!)?(attachment|document|version|commit)?((#|r)(\d+)|(:)([^"][^\s<>]+|"[^"]+"))(?=[[:punct:]]|\s|<|$)}) do |m|
284 # Source files:
285 # source:some/file -> Link to the file located at /some/file in the project's repository
286 # source:some/file@52 -> Link to the file's revision 52
287 # source:some/file#L120 -> Link to line 120 of the file
288 # source:some/file@52#L120 -> Link to line 120 of the file's revision 52
289 # export:some/file -> Force the download of the file
290 text = text.gsub(%r{([\s\(,-^])(!)?(attachment|document|version|commit|source|export)?((#|r)(\d+)|(:)([^"][^\s<>]+|"[^"]+"))(?=[[:punct:]]|\s|<|$)}) do |m|
285 291 leading, esc, prefix, sep, oid = $1, $2, $3, $5 || $7, $6 || $8
286 292 link = nil
287 293 if esc.nil?
288 294 if prefix.nil? && sep == 'r'
289 295 if project && (changeset = project.changesets.find_by_revision(oid))
290 link = link_to("r#{oid}", {:only_path => only_path, :controller => 'repositories', :action => 'revision', :id => project.id, :rev => oid},
296 link = link_to("r#{oid}", {:only_path => only_path, :controller => 'repositories', :action => 'revision', :id => project, :rev => oid},
291 297 :class => 'changeset',
292 298 :title => truncate(changeset.comments, 100))
293 299 end
@@ -328,7 +334,17 module ApplicationHelper
328 334 end
329 335 when 'commit'
330 336 if project && (changeset = project.changesets.find(:first, :conditions => ["scmid LIKE ?", "#{name}%"]))
331 link = link_to h("#{name}"), {:only_path => only_path, :controller => 'repositories', :action => 'revision', :id => project.id, :rev => changeset.revision}, :class => 'changeset', :title => truncate(changeset.comments, 100)
337 link = link_to h("#{name}"), {:only_path => only_path, :controller => 'repositories', :action => 'revision', :id => project, :rev => changeset.revision}, :class => 'changeset', :title => truncate(changeset.comments, 100)
338 end
339 when 'source', 'export'
340 if project && project.repository
341 name =~ %r{^[/\\]*(.*?)(@([0-9a-f]+))?(#(L\d+))?$}
342 path, rev, anchor = $1, $3, $5
343 link = link_to h("#{prefix}:#{name}"), {:controller => 'repositories', :action => 'entry', :id => project, :path => path,
344 :rev => rev,
345 :anchor => anchor,
346 :format => (prefix == 'export' ? 'raw' : nil)},
347 :class => (prefix == 'export' ? 'source download' : 'source')
332 348 end
333 349 when 'attachment'
334 350 if attachments && attachment = attachments.detect {|a| a.filename == name }
@@ -2,16 +2,13
2 2
3 3 <div class="autoscroll">
4 4 <table class="filecontent CodeRay">
5 <tbody>
6 <% line_num = 1 %>
7 <% syntax_highlight(@path, to_utf8(@content)).each_line do |line| %>
8 <tr>
9 <th class="line-num"><%= line_num %></th>
10 <td class="line-code"><pre><%= line %></pre></td>
11 </tr>
12 <% line_num += 1 %>
13 <% end %>
14 </tbody>
5 <tbody>
6 <% line_num = 1 %>
7 <% syntax_highlight(@path, to_utf8(@content)).each_line do |line| %>
8 <tr><th class="line-num" id="L<%= line_num %>"><%= line_num %></th><td class="line-code"><pre><%= line %></pre></td></tr>
9 <% line_num += 1 %>
10 <% end %>
11 </tbody>
15 12 </table>
16 13 </div>
17 14
@@ -67,7 +67,7 class ApplicationHelperTest < HelperTestCase
67 67 issue_link = link_to('#3', {:controller => 'issues', :action => 'show', :id => 3},
68 68 :class => 'issue', :title => 'Error 281 when updating a recipe (New)')
69 69
70 changeset_link = link_to('r1', {:controller => 'repositories', :action => 'revision', :id => 1, :rev => 1},
70 changeset_link = link_to('r1', {:controller => 'repositories', :action => 'revision', :id => 'ecookbook', :rev => 1},
71 71 :class => 'changeset', :title => 'My very first commit')
72 72
73 73 document_link = link_to('Test document', {:controller => 'documents', :action => 'show', :id => 1},
@@ -75,23 +75,36 class ApplicationHelperTest < HelperTestCase
75 75
76 76 version_link = link_to('1.0', {:controller => 'versions', :action => 'show', :id => 2},
77 77 :class => 'version')
78
79 source_url = {:controller => 'repositories', :action => 'entry', :id => 'ecookbook', :path => 'some/file'}
78 80
79 81 to_test = {
80 '#3, #3 and #3.' => "#{issue_link}, #{issue_link} and #{issue_link}.",
81 'r1' => changeset_link,
82 'document#1' => document_link,
83 'document:"Test document"' => document_link,
84 'version#2' => version_link,
85 'version:1.0' => version_link,
86 'version:"1.0"' => version_link,
82 # tickets
83 '#3, #3 and #3.' => "#{issue_link}, #{issue_link} and #{issue_link}.",
84 # changesets
85 'r1' => changeset_link,
86 # documents
87 'document#1' => document_link,
88 'document:"Test document"' => document_link,
89 # versions
90 'version#2' => version_link,
91 'version:1.0' => version_link,
92 'version:"1.0"' => version_link,
93 # source
94 'source:/some/file' => link_to('source:/some/file', source_url, :class => 'source'),
95 'source:/some/file@52' => link_to('source:/some/file@52', source_url.merge(:rev => 52), :class => 'source'),
96 'source:/some/file#L110' => link_to('source:/some/file#L110', source_url.merge(:anchor => 'L110'), :class => 'source'),
97 'source:/some/file@52#L110' => link_to('source:/some/file@52#L110', source_url.merge(:rev => 52, :anchor => 'L110'), :class => 'source'),
98 'export:/some/file' => link_to('export:/some/file', source_url.merge(:format => 'raw'), :class => 'source download'),
87 99 # escaping
88 '!#3.' => '#3.',
89 '!r1' => 'r1',
90 '!document#1' => 'document#1',
91 '!document:"Test document"' => 'document:"Test document"',
92 '!version#2' => 'version#2',
93 '!version:1.0' => 'version:1.0',
94 '!version:"1.0"' => 'version:"1.0"',
100 '!#3.' => '#3.',
101 '!r1' => 'r1',
102 '!document#1' => 'document#1',
103 '!document:"Test document"' => 'document:"Test document"',
104 '!version#2' => 'version#2',
105 '!version:1.0' => 'version:1.0',
106 '!version:"1.0"' => 'version:"1.0"',
107 '!source:/some/file' => 'source:/some/file',
95 108 }
96 109 @project = Project.find(1)
97 110 to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text) }
@@ -36,7 +36,7 class MailerTest < Test::Unit::TestCase
36 36 # link to a referenced ticket
37 37 assert mail.body.include?('<a href="https://mydomain.foo/issues/show/2" class="issue" title="Add ingredients categories (Assigned)">#2</a>')
38 38 # link to a changeset
39 assert mail.body.include?('<a href="https://mydomain.foo/repositories/revision/1?rev=2" class="changeset" title="This commit fixes #1, #2 and references #1 &amp; #3">r2</a>')
39 assert mail.body.include?('<a href="https://mydomain.foo/repositories/revision/ecookbook?rev=2" class="changeset" title="This commit fixes #1, #2 and references #1 &amp; #3">r2</a>')
40 40 end
41 41
42 42 # test mailer methods for each language
General Comments 0
You need to be logged in to leave comments. Login now