diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index c6f743d..d465cad 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -508,13 +508,14 @@ module ApplicationHelper # export:some/file -> Force the download of the file # Forum messages: # message#1218 -> Link to message with id 1218 - text = text.gsub(%r{([\s\(,\-\>]|^)(!)?(attachment|document|version|commit|source|export|message)?((#|r)(\d+)|(:)([^"\s<>][^\s<>]*?|"[^"]+?"))(?=(?=[[:punct:]]\W)|,|\s|<|$)}) do |m| - leading, esc, prefix, sep, oid = $1, $2, $3, $5 || $7, $6 || $8 + text = text.gsub(%r{([\s\(,\-\>]|^)(!)?("([^"]+)":)?(attachment|document|version|commit|source|export|message)?((#|r)(\d+)|(:)([^"\s<>][^\s<>]*?|"[^"]+?"))(?=(?=[[:punct:]]\W)|,|\s|<|$)}) do |m| + leading, esc, label, prefix, sep, oid = $1, $2, $4, $5, $7 || $9, $8 || $10 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, :rev => oid}, + label = label || "r#{oid}" + link = link_to(label, {:only_path => only_path, :controller => 'repositories', :action => 'revision', :id => project, :rev => oid}, :class => 'changeset', :title => truncate_single_line(changeset.comments, :length => 100)) end @@ -523,23 +524,28 @@ module ApplicationHelper case prefix when nil if issue = Issue.visible.find_by_id(oid, :include => :status) - link = link_to("##{oid}", {:only_path => only_path, :controller => 'issues', :action => 'show', :id => oid}, + title = label ? "##{oid} #{truncate(issue.subject, :length => 100)} (#{issue.status.name})" : "#{truncate(issue.subject, :length => 100)} (#{issue.status.name})" + label = label || "##{oid}" + link = link_to(label, {:only_path => only_path, :controller => 'issues', :action => 'show', :id => oid}, :class => issue.css_classes, - :title => "#{truncate(issue.subject, :length => 100)} (#{issue.status.name})") + :title => title) end when 'document' if document = Document.find_by_id(oid, :include => [:project], :conditions => Project.visible_by(User.current)) - link = link_to h(document.title), {:only_path => only_path, :controller => 'documents', :action => 'show', :id => document}, + label = label || h(document.title) + link = link_to label, {:only_path => only_path, :controller => 'documents', :action => 'show', :id => document}, :class => 'document' end when 'version' if version = Version.find_by_id(oid, :include => [:project], :conditions => Project.visible_by(User.current)) - link = link_to h(version.name), {:only_path => only_path, :controller => 'versions', :action => 'show', :id => version}, + label = label || h(version.name) + link = link_to label, {:only_path => only_path, :controller => 'versions', :action => 'show', :id => version}, :class => 'version' end when 'message' if message = Message.find_by_id(oid, :include => [:parent, {:board => :project}], :conditions => Project.visible_by(User.current)) - link = link_to h(truncate(message.subject, :length => 60)), {:only_path => only_path, + label = label || h(truncate(message.subject, :length => 60)) + link = link_to label, {:only_path => only_path, :controller => 'messages', :action => 'show', :board_id => message.board, @@ -554,17 +560,20 @@ module ApplicationHelper case prefix when 'document' if project && document = project.documents.find_by_title(name) - link = link_to h(document.title), {:only_path => only_path, :controller => 'documents', :action => 'show', :id => document}, + label = label || h(document.title) + link = link_to label, {:only_path => only_path, :controller => 'documents', :action => 'show', :id => document}, :class => 'document' end when 'version' if project && version = project.versions.find_by_name(name) - link = link_to h(version.name), {:only_path => only_path, :controller => 'versions', :action => 'show', :id => version}, + label = label || h(version.name) + link = link_to label, {:only_path => only_path, :controller => 'versions', :action => 'show', :id => version}, :class => 'version' 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, :rev => changeset.revision}, + label = label || h("#{name}") + link = link_to label, {:only_path => only_path, :controller => 'repositories', :action => 'revision', :id => project, :rev => changeset.revision}, :class => 'changeset', :title => truncate_single_line(changeset.comments, :length => 100) end @@ -572,7 +581,8 @@ module ApplicationHelper 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, + label = label || h("#{prefix}:#{name}") + link = link_to label, {:controller => 'repositories', :action => 'entry', :id => project, :path => to_path_param(path), :rev => rev, :anchor => anchor, @@ -581,7 +591,8 @@ module ApplicationHelper end when 'attachment' if attachments && attachment = attachments.detect {|a| a.filename == name } - link = link_to h(attachment.filename), {:only_path => only_path, :controller => 'attachments', :action => 'download', :id => attachment}, + label = label || h(attachment.filename) + link = link_to label, {:only_path => only_path, :controller => 'attachments', :action => 'download', :id => attachment}, :class => 'attachment' end end diff --git a/test/unit/helpers/application_helper_test.rb b/test/unit/helpers/application_helper_test.rb index 2f7c6fd..476192b 100644 --- a/test/unit/helpers/application_helper_test.rb +++ b/test/unit/helpers/application_helper_test.rb @@ -136,9 +136,14 @@ RAW def test_redmine_links issue_link = link_to('#3', {:controller => 'issues', :action => 'show', :id => 3}, :class => 'issue status-1 priority-1 overdue', :title => 'Error 281 when updating a recipe (New)') + + named_issue_link = link_to('My Ticket', {:controller => 'issues', :action => 'show', :id => 3}, + :class => 'issue status-1 priority-1 overdue', :title => '#3 Error 281 when updating a recipe (New)') changeset_link = link_to('r1', {:controller => 'repositories', :action => 'revision', :id => 'ecookbook', :rev => 1}, :class => 'changeset', :title => 'My very first commit') + named_changeset_link = link_to('My revision', {:controller => 'repositories', :action => 'revision', :id => 'ecookbook', :rev => 1}, + :class => 'changeset', :title => 'My very first commit') changeset_link2 = link_to('r2', {:controller => 'repositories', :action => 'revision', :id => 'ecookbook', :rev => 2}, :class => 'changeset', :title => 'This commit fixes #1, #2 and references #1 & #3') @@ -156,8 +161,12 @@ RAW to_test = { # tickets '#3, #3 and #3.' => "#{issue_link}, #{issue_link} and #{issue_link}.", + '"My Ticket":#3, #3 and "My Ticket":#3.' \ + => "#{named_issue_link}, #{issue_link} and #{named_issue_link}.", # changesets 'r1' => changeset_link, + '"My revision":r1' => named_changeset_link, + '"My revision":r1, r2' => "#{named_changeset_link}, #{changeset_link2}", 'r1.' => "#{changeset_link}.", 'r1, r2' => "#{changeset_link}, #{changeset_link2}", 'r1,r2' => "#{changeset_link},#{changeset_link2}",