Adds support for "Magic links" to notes (#2715).

git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@8877 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Jean-Philippe Lang 2012-02-15 17:49:31 +00:00
parent 6aae25209a
commit 5c3ac1a40e
2 changed files with 12 additions and 4 deletions

View File

@ -659,8 +659,8 @@ module ApplicationHelper
# identifier:version:1.0.0 # identifier:version:1.0.0
# identifier:source:some/file # identifier:source:some/file
def parse_redmine_links(text, project, obj, attr, only_path, options) def parse_redmine_links(text, project, obj, attr, only_path, options)
text.gsub!(%r{([\s\(,\-\[\>]|^)(!)?(([a-z0-9\-_]+):)?(attachment|document|version|forum|news|message|project|commit|source|export)?(((#)|((([a-z0-9\-]+)\|)?(r)))(\d+)|(:)([^"\s<>][^\s<>]*?|"[^"]+?"))(?=(?=[[:punct:]][^A-Za-z0-9_/])|,|\s|\]|<|$)}) do |m| text.gsub!(%r{([\s\(,\-\[\>]|^)(!)?(([a-z0-9\-_]+):)?(attachment|document|version|forum|news|message|project|commit|source|export)?(((#)|((([a-z0-9\-]+)\|)?(r)))((\d+)((#note)?-(\d+))?)|(:)([^"\s<>][^\s<>]*?|"[^"]+?"))(?=(?=[[:punct:]][^A-Za-z0-9_/])|,|\s|\]|<|$)}) do |m|
leading, esc, project_prefix, project_identifier, prefix, repo_prefix, repo_identifier, sep, identifier = $1, $2, $3, $4, $5, $10, $11, $8 || $12 || $14, $13 || $15 leading, esc, project_prefix, project_identifier, prefix, repo_prefix, repo_identifier, sep, identifier, comment_suffix, comment_id = $1, $2, $3, $4, $5, $10, $11, $8 || $12 || $18, $14 || $19, $15, $17
link = nil link = nil
if project_identifier if project_identifier
project = Project.visible.find_by_identifier(project_identifier) project = Project.visible.find_by_identifier(project_identifier)
@ -686,7 +686,8 @@ module ApplicationHelper
case prefix case prefix
when nil when nil
if issue = Issue.visible.find_by_id(oid, :include => :status) if issue = Issue.visible.find_by_id(oid, :include => :status)
link = link_to("##{oid}", {:only_path => only_path, :controller => 'issues', :action => 'show', :id => oid}, anchor = comment_id ? "note-#{comment_id}" : nil
link = link_to("##{oid}", {:only_path => only_path, :controller => 'issues', :action => 'show', :id => oid, :anchor => anchor},
:class => issue.css_classes, :class => issue.css_classes,
:title => "#{truncate(issue.subject, :length => 100)} (#{issue.status.name})") :title => "#{truncate(issue.subject, :length => 100)} (#{issue.status.name})")
end end
@ -785,7 +786,7 @@ module ApplicationHelper
end end
end end
end end
(leading + (link || "#{project_prefix}#{prefix}#{repo_prefix}#{sep}#{identifier}")).html_safe (leading + (link || "#{project_prefix}#{prefix}#{repo_prefix}#{sep}#{identifier}#{comment_suffix}")).html_safe
end end
end end

View File

@ -227,6 +227,8 @@ RAW
def test_redmine_links def test_redmine_links
issue_link = link_to('#3', {:controller => 'issues', :action => 'show', :id => 3}, 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)') :class => 'issue status-1 priority-1 overdue', :title => 'Error 281 when updating a recipe (New)')
note_link = link_to('#3', {:controller => 'issues', :action => 'show', :id => 3, :anchor => 'note-14'},
:class => 'issue status-1 priority-1 overdue', :title => 'Error 281 when updating a recipe (New)')
changeset_link = link_to('r1', {:controller => 'repositories', :action => 'revision', :id => 'ecookbook', :rev => 1}, changeset_link = link_to('r1', {:controller => 'repositories', :action => 'revision', :id => 'ecookbook', :rev => 1},
:class => 'changeset', :title => 'My very first commit') :class => 'changeset', :title => 'My very first commit')
@ -253,6 +255,9 @@ RAW
to_test = { to_test = {
# tickets # tickets
'#3, [#3], (#3) and #3.' => "#{issue_link}, [#{issue_link}], (#{issue_link}) and #{issue_link}.", '#3, [#3], (#3) and #3.' => "#{issue_link}, [#{issue_link}], (#{issue_link}) and #{issue_link}.",
# ticket notes
'#3-14' => note_link,
'#3#note-14' => note_link,
# changesets # changesets
'r1' => changeset_link, 'r1' => changeset_link,
'r1.' => "#{changeset_link}.", 'r1.' => "#{changeset_link}.",
@ -294,6 +299,8 @@ RAW
'project:"eCookbook subProject 1"' => link_to('eCookbook Subproject 1', project_url, :class => 'project'), 'project:"eCookbook subProject 1"' => link_to('eCookbook Subproject 1', project_url, :class => 'project'),
# escaping # escaping
'!#3.' => '#3.', '!#3.' => '#3.',
'!#3-14.' => '#3-14.',
'!#3#-note14.' => '#3#-note14.',
'!r1' => 'r1', '!r1' => 'r1',
'!document#1' => 'document#1', '!document#1' => 'document#1',
'!document:"Test document"' => 'document:"Test document"', '!document:"Test document"' => 'document:"Test document"',