]> source.dussan.org Git - redmine.git/commitdiff
Add Redmine links for repository files using source: and export: keyworkds (#867).
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Mon, 17 Mar 2008 17:45:01 +0000 (17:45 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Mon, 17 Mar 2008 17:45:01 +0000 (17:45 +0000)
git-svn-id: http://redmine.rubyforge.org/svn/trunk@1267 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/controllers/repositories_controller.rb
app/helpers/application_helper.rb
app/views/repositories/entry.rhtml
test/unit/helpers/application_helper_test.rb
test/unit/mailer_test.rb

index bce5f66a9aab1574d2519557a1bb06ecb5ed5c43..349d0a505eaf4241e0c6dd41784905668eb5d6c4 100644 (file)
@@ -97,7 +97,8 @@ class RepositoriesController < ApplicationController
   def entry
     @content = @repository.scm.cat(@path, @rev)
     show_error_not_found and return unless @content
-    if 'raw' == params[:format]      
+    if 'raw' == params[:format] || @content.is_binary_data?
+      # Force the download if it's a binary file
       send_data @content, :filename => @path.split('/').last
     else
       # Prevent empty lines when displaying a file with Windows style eol
index aa19ce7d4221e03e1edf5a7ffbda08558b4591fc..4e2a104457be11be2df0a18a32573d1b6bab2c65 100644 (file)
@@ -281,13 +281,19 @@ module ApplicationHelper
     #     version:"1.0 beta 2" -> Link to version named "1.0 beta 2"
     #   Attachments:
     #     attachment:file.zip -> Link to the attachment of the current object named file.zip
-    text = text.gsub(%r{([\s\(,-^])(!)?(attachment|document|version|commit)?((#|r)(\d+)|(:)([^"][^\s<>]+|"[^"]+"))(?=[[:punct:]]|\s|<|$)}) do |m|
+    #   Source files:
+    #     source:some/file -> Link to the file located at /some/file in the project's repository
+    #     source:some/file@52 -> Link to the file's revision 52
+    #     source:some/file#L120 -> Link to line 120 of the file
+    #     source:some/file@52#L120 -> Link to line 120 of the file's revision 52
+    #     export:some/file -> Force the download of the file
+    text = text.gsub(%r{([\s\(,-^])(!)?(attachment|document|version|commit|source|export)?((#|r)(\d+)|(:)([^"][^\s<>]+|"[^"]+"))(?=[[:punct:]]|\s|<|$)}) do |m|
       leading, esc, prefix, sep, oid = $1, $2, $3, $5 || $7, $6 || $8
       link = nil
       if esc.nil?
         if prefix.nil? && sep == 'r'
           if project && (changeset = project.changesets.find_by_revision(oid))
-            link = link_to("r#{oid}", {:only_path => only_path, :controller => 'repositories', :action => 'revision', :id => project.id, :rev => oid},
+            link = link_to("r#{oid}", {:only_path => only_path, :controller => 'repositories', :action => 'revision', :id => project, :rev => oid},
                                       :class => 'changeset',
                                       :title => truncate(changeset.comments, 100))
           end
@@ -328,7 +334,17 @@ module ApplicationHelper
             end
           when 'commit'
             if project && (changeset = project.changesets.find(:first, :conditions => ["scmid LIKE ?", "#{name}%"]))
-              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)
+              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)
+            end
+          when 'source', 'export'
+            if project && project.repository
+              name =~ %r{^[/\\]*(.*?)(@([0-9a-f]+))?(#(L\d+))?$}
+              path, rev, anchor = $1, $3, $5
+              link = link_to h("#{prefix}:#{name}"), {:controller => 'repositories', :action => 'entry', :id => project, :path => path,
+                                                      :rev => rev,
+                                                      :anchor => anchor,
+                                                      :format => (prefix == 'export' ? 'raw' : nil)},
+                                                     :class => (prefix == 'export' ? 'source download' : 'source')
             end
           when 'attachment'
             if attachments && attachment = attachments.detect {|a| a.filename == name }
index 41565a2323beabbf6ea1015838a1fca93528cc16..309da76fc520cb35b2d914ddf7099e27349c166b 100644 (file)
@@ -2,16 +2,13 @@
 
 <div class="autoscroll">
 <table class="filecontent CodeRay">
-  <tbody>
-    <% line_num = 1 %>
-    <% syntax_highlight(@path, to_utf8(@content)).each_line do |line| %>
-    <tr>
-      <th class="line-num"><%= line_num %></th>
-      <td class="line-code"><pre><%= line %></pre></td>
-    </tr>
-    <% line_num += 1 %>
-    <% end %>
-  </tbody>
+<tbody>
+<% line_num = 1 %>
+<% syntax_highlight(@path, to_utf8(@content)).each_line do |line| %>
+<tr><th class="line-num" id="L<%= line_num %>"><%= line_num %></th><td class="line-code"><pre><%= line %></pre></td></tr>
+<% line_num += 1 %>
+<% end %>
+</tbody>
 </table>
 </div>
 
index 4e617f69936241b7ccdee581a23a08284dec828d..f34a587a294abc2a97ad087e0f42c35fdecb15d6 100644 (file)
@@ -67,7 +67,7 @@ class ApplicationHelperTest < HelperTestCase
     issue_link = link_to('#3', {:controller => 'issues', :action => 'show', :id => 3}, 
                                :class => 'issue', :title => 'Error 281 when updating a recipe (New)')
     
-    changeset_link = link_to('r1', {:controller => 'repositories', :action => 'revision', :id => 1, :rev => 1},
+    changeset_link = link_to('r1', {:controller => 'repositories', :action => 'revision', :id => 'ecookbook', :rev => 1},
                                    :class => 'changeset', :title => 'My very first commit')
     
     document_link = link_to('Test document', {:controller => 'documents', :action => 'show', :id => 1},
@@ -75,23 +75,36 @@ class ApplicationHelperTest < HelperTestCase
     
     version_link = link_to('1.0', {:controller => 'versions', :action => 'show', :id => 2},
                                   :class => 'version')
+
+    source_url = {:controller => 'repositories', :action => 'entry', :id => 'ecookbook', :path => 'some/file'}
     
     to_test = {
-      '#3, #3 and #3.' => "#{issue_link}, #{issue_link} and #{issue_link}.",
-      'r1' => changeset_link,
-      'document#1' => document_link,
-      'document:"Test document"' => document_link,
-      'version#2' => version_link,
-      'version:1.0' => version_link,
-      'version:"1.0"' => version_link,
+      # tickets
+      '#3, #3 and #3.'              => "#{issue_link}, #{issue_link} and #{issue_link}.",
+      # changesets
+      'r1'                          => changeset_link,
+      # documents
+      'document#1'                  => document_link,
+      'document:"Test document"'    => document_link,
+      # versions
+      'version#2'                   => version_link,
+      'version:1.0'                 => version_link,
+      'version:"1.0"'               => version_link,
+      # source
+      'source:/some/file'           => link_to('source:/some/file', source_url, :class => 'source'),
+      'source:/some/file@52'        => link_to('source:/some/file@52', source_url.merge(:rev => 52), :class => 'source'),
+      'source:/some/file#L110'      => link_to('source:/some/file#L110', source_url.merge(:anchor => 'L110'), :class => 'source'),
+      'source:/some/file@52#L110'   => link_to('source:/some/file@52#L110', source_url.merge(:rev => 52, :anchor => 'L110'), :class => 'source'),
+      'export:/some/file'           => link_to('export:/some/file', source_url.merge(:format => 'raw'), :class => 'source download'),
       # escaping
-      '!#3.' => '#3.',
-      '!r1' => 'r1',
-      '!document#1' => 'document#1',
-      '!document:"Test document"' => 'document:"Test document"',
-      '!version#2' => 'version#2',
-      '!version:1.0' => 'version:1.0',
-      '!version:"1.0"' => 'version:"1.0"',
+      '!#3.'                        => '#3.',
+      '!r1'                         => 'r1',
+      '!document#1'                 => 'document#1',
+      '!document:"Test document"'   => 'document:"Test document"',
+      '!version#2'                  => 'version#2',
+      '!version:1.0'                => 'version:1.0',
+      '!version:"1.0"'              => 'version:"1.0"',
+      '!source:/some/file'          => 'source:/some/file',
     }
     @project = Project.find(1)
     to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text) }
index dc3fde414f4f5b2a392805120f63f53c75ed80e7..64648b94c783d61426e46c6f71b3d736704e19a7 100644 (file)
@@ -36,7 +36,7 @@ class MailerTest < Test::Unit::TestCase
     # link to a referenced ticket
     assert mail.body.include?('<a href="https://mydomain.foo/issues/show/2" class="issue" title="Add ingredients categories (Assigned)">#2</a>')
     # link to a changeset
-    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>')
+    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>')
   end
   
   # test mailer methods for each language