diff options
author | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2008-03-17 17:45:01 +0000 |
---|---|---|
committer | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2008-03-17 17:45:01 +0000 |
commit | 93d1b2e0a43982f37b60f6b15b36bc46e3c79f9b (patch) | |
tree | c42a1ccb9870d098482668697b7b9af4d2744263 /app | |
parent | cab300e65045e53afe858f52bfbf5b81488f7ea0 (diff) | |
download | redmine-93d1b2e0a43982f37b60f6b15b36bc46e3c79f9b.tar.gz redmine-93d1b2e0a43982f37b60f6b15b36bc46e3c79f9b.zip |
Add Redmine links for repository files using source: and export: keyworkds (#867).
git-svn-id: http://redmine.rubyforge.org/svn/trunk@1267 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'app')
-rw-r--r-- | app/controllers/repositories_controller.rb | 3 | ||||
-rw-r--r-- | app/helpers/application_helper.rb | 22 | ||||
-rw-r--r-- | app/views/repositories/entry.rhtml | 17 |
3 files changed, 28 insertions, 14 deletions
diff --git a/app/controllers/repositories_controller.rb b/app/controllers/repositories_controller.rb index bce5f66a9..349d0a505 100644 --- a/app/controllers/repositories_controller.rb +++ b/app/controllers/repositories_controller.rb @@ -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 diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index aa19ce7d4..4e2a10445 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -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 } diff --git a/app/views/repositories/entry.rhtml b/app/views/repositories/entry.rhtml index 41565a232..309da76fc 100644 --- a/app/views/repositories/entry.rhtml +++ b/app/views/repositories/entry.rhtml @@ -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> |