@@ -97,7 +97,8 class RepositoriesController < ApplicationController | |||||
97 | def entry |
|
97 | def entry | |
98 | @content = @repository.scm.cat(@path, @rev) |
|
98 | @content = @repository.scm.cat(@path, @rev) | |
99 | show_error_not_found and return unless @content |
|
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 | send_data @content, :filename => @path.split('/').last |
|
102 | send_data @content, :filename => @path.split('/').last | |
102 | else |
|
103 | else | |
103 | # Prevent empty lines when displaying a file with Windows style eol |
|
104 | # Prevent empty lines when displaying a file with Windows style eol |
@@ -281,13 +281,19 module ApplicationHelper | |||||
281 | # version:"1.0 beta 2" -> Link to version named "1.0 beta 2" |
|
281 | # version:"1.0 beta 2" -> Link to version named "1.0 beta 2" | |
282 | # Attachments: |
|
282 | # Attachments: | |
283 | # attachment:file.zip -> Link to the attachment of the current object named file.zip |
|
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 | leading, esc, prefix, sep, oid = $1, $2, $3, $5 || $7, $6 || $8 |
|
291 | leading, esc, prefix, sep, oid = $1, $2, $3, $5 || $7, $6 || $8 | |
286 | link = nil |
|
292 | link = nil | |
287 | if esc.nil? |
|
293 | if esc.nil? | |
288 | if prefix.nil? && sep == 'r' |
|
294 | if prefix.nil? && sep == 'r' | |
289 | if project && (changeset = project.changesets.find_by_revision(oid)) |
|
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 |
|
296 | link = link_to("r#{oid}", {:only_path => only_path, :controller => 'repositories', :action => 'revision', :id => project, :rev => oid}, | |
291 | :class => 'changeset', |
|
297 | :class => 'changeset', | |
292 | :title => truncate(changeset.comments, 100)) |
|
298 | :title => truncate(changeset.comments, 100)) | |
293 | end |
|
299 | end | |
@@ -328,7 +334,17 module ApplicationHelper | |||||
328 | end |
|
334 | end | |
329 | when 'commit' |
|
335 | when 'commit' | |
330 | if project && (changeset = project.changesets.find(:first, :conditions => ["scmid LIKE ?", "#{name}%"])) |
|
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 |
|
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 | end |
|
348 | end | |
333 | when 'attachment' |
|
349 | when 'attachment' | |
334 | if attachments && attachment = attachments.detect {|a| a.filename == name } |
|
350 | if attachments && attachment = attachments.detect {|a| a.filename == name } |
@@ -5,10 +5,7 | |||||
5 |
|
|
5 | <tbody> | |
6 |
|
|
6 | <% line_num = 1 %> | |
7 |
|
|
7 | <% syntax_highlight(@path, to_utf8(@content)).each_line do |line| %> | |
8 | <tr> |
|
8 | <tr><th class="line-num" id="L<%= line_num %>"><%= line_num %></th><td class="line-code"><pre><%= line %></pre></td></tr> | |
9 | <th class="line-num"><%= line_num %></th> |
|
|||
10 | <td class="line-code"><pre><%= line %></pre></td> |
|
|||
11 | </tr> |
|
|||
12 |
|
|
9 | <% line_num += 1 %> | |
13 |
|
|
10 | <% end %> | |
14 |
|
|
11 | </tbody> |
@@ -67,7 +67,7 class ApplicationHelperTest < HelperTestCase | |||||
67 | issue_link = link_to('#3', {:controller => 'issues', :action => 'show', :id => 3}, |
|
67 | issue_link = link_to('#3', {:controller => 'issues', :action => 'show', :id => 3}, | |
68 | :class => 'issue', :title => 'Error 281 when updating a recipe (New)') |
|
68 | :class => 'issue', :title => 'Error 281 when updating a recipe (New)') | |
69 |
|
69 | |||
70 |
changeset_link = link_to('r1', {:controller => 'repositories', :action => 'revision', :id => |
|
70 | changeset_link = link_to('r1', {:controller => 'repositories', :action => 'revision', :id => 'ecookbook', :rev => 1}, | |
71 | :class => 'changeset', :title => 'My very first commit') |
|
71 | :class => 'changeset', :title => 'My very first commit') | |
72 |
|
72 | |||
73 | document_link = link_to('Test document', {:controller => 'documents', :action => 'show', :id => 1}, |
|
73 | document_link = link_to('Test document', {:controller => 'documents', :action => 'show', :id => 1}, | |
@@ -76,14 +76,26 class ApplicationHelperTest < HelperTestCase | |||||
76 | version_link = link_to('1.0', {:controller => 'versions', :action => 'show', :id => 2}, |
|
76 | version_link = link_to('1.0', {:controller => 'versions', :action => 'show', :id => 2}, | |
77 | :class => 'version') |
|
77 | :class => 'version') | |
78 |
|
78 | |||
|
79 | source_url = {:controller => 'repositories', :action => 'entry', :id => 'ecookbook', :path => 'some/file'} | |||
|
80 | ||||
79 | to_test = { |
|
81 | to_test = { | |
|
82 | # tickets | |||
80 | '#3, #3 and #3.' => "#{issue_link}, #{issue_link} and #{issue_link}.", |
|
83 | '#3, #3 and #3.' => "#{issue_link}, #{issue_link} and #{issue_link}.", | |
|
84 | # changesets | |||
81 | 'r1' => changeset_link, |
|
85 | 'r1' => changeset_link, | |
|
86 | # documents | |||
82 | 'document#1' => document_link, |
|
87 | 'document#1' => document_link, | |
83 | 'document:"Test document"' => document_link, |
|
88 | 'document:"Test document"' => document_link, | |
|
89 | # versions | |||
84 | 'version#2' => version_link, |
|
90 | 'version#2' => version_link, | |
85 | 'version:1.0' => version_link, |
|
91 | 'version:1.0' => version_link, | |
86 | '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 | # escaping |
|
99 | # escaping | |
88 | '!#3.' => '#3.', |
|
100 | '!#3.' => '#3.', | |
89 | '!r1' => 'r1', |
|
101 | '!r1' => 'r1', | |
@@ -92,6 +104,7 class ApplicationHelperTest < HelperTestCase | |||||
92 | '!version#2' => 'version#2', |
|
104 | '!version#2' => 'version#2', | |
93 | '!version:1.0' => 'version:1.0', |
|
105 | '!version:1.0' => 'version:1.0', | |
94 | '!version:"1.0"' => 'version:"1.0"', |
|
106 | '!version:"1.0"' => 'version:"1.0"', | |
|
107 | '!source:/some/file' => 'source:/some/file', | |||
95 | } |
|
108 | } | |
96 | @project = Project.find(1) |
|
109 | @project = Project.find(1) | |
97 | to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text) } |
|
110 | to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text) } |
@@ -36,7 +36,7 class MailerTest < Test::Unit::TestCase | |||||
36 | # link to a referenced ticket |
|
36 | # link to a referenced ticket | |
37 | assert mail.body.include?('<a href="https://mydomain.foo/issues/show/2" class="issue" title="Add ingredients categories (Assigned)">#2</a>') |
|
37 | assert mail.body.include?('<a href="https://mydomain.foo/issues/show/2" class="issue" title="Add ingredients categories (Assigned)">#2</a>') | |
38 | # link to a changeset |
|
38 | # link to a changeset | |
39 |
assert mail.body.include?('<a href="https://mydomain.foo/repositories/revision/ |
|
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 & #3">r2</a>') | |
40 | end |
|
40 | end | |
41 |
|
41 | |||
42 | # test mailer methods for each language |
|
42 | # test mailer methods for each language |
General Comments 0
You need to be logged in to leave comments.
Login now