Adds projects links (#4812).

git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@3422 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Jean-Philippe Lang 2010-02-13 10:32:06 +00:00
parent 89b9700074
commit 3168ee3d47
2 changed files with 20 additions and 3 deletions

View File

@ -510,7 +510,7 @@ module ApplicationHelper
# export:some/file -> Force the download of the file # export:some/file -> Force the download of the file
# Forum messages: # Forum messages:
# message#1218 -> Link to message with id 1218 # 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| text = text.gsub(%r{([\s\(,\-\>]|^)(!)?(attachment|document|version|commit|source|export|message|project)?((#|r)(\d+)|(:)([^"\s<>][^\s<>]*?|"[^"]+?"))(?=(?=[[:punct:]]\W)|,|\s|<|$)}) do |m|
leading, esc, prefix, sep, oid = $1, $2, $3, $5 || $7, $6 || $8 leading, esc, prefix, sep, oid = $1, $2, $3, $5 || $7, $6 || $8
link = nil link = nil
if esc.nil? if esc.nil?
@ -549,6 +549,11 @@ module ApplicationHelper
:anchor => (message.parent ? "message-#{message.id}" : nil)}, :anchor => (message.parent ? "message-#{message.id}" : nil)},
:class => 'message' :class => 'message'
end end
when 'project'
if p = Project.visible.find_by_id(oid)
link = link_to h(p.name), {:only_path => only_path, :controller => 'projects', :action => 'show', :id => p},
:class => 'project'
end
end end
elsif sep == ':' elsif sep == ':'
# removes the double quotes if any # removes the double quotes if any
@ -586,6 +591,11 @@ module ApplicationHelper
link = link_to h(attachment.filename), {:only_path => only_path, :controller => 'attachments', :action => 'download', :id => attachment}, link = link_to h(attachment.filename), {:only_path => only_path, :controller => 'attachments', :action => 'download', :id => attachment},
:class => 'attachment' :class => 'attachment'
end end
when 'project'
if p = Project.visible.find(:first, :conditions => ["identifier = :s OR LOWER(name) = :s", {:s => name.downcase}])
link = link_to h(p.name), {:only_path => only_path, :controller => 'projects', :action => 'show', :id => p},
:class => 'project'
end
end end
end end
end end

View File

@ -27,7 +27,8 @@ class ApplicationHelperTest < HelperTestCase
:trackers, :issue_statuses, :issues, :versions, :documents, :trackers, :issue_statuses, :issues, :versions, :documents,
:wikis, :wiki_pages, :wiki_contents, :wikis, :wiki_pages, :wiki_contents,
:boards, :messages, :boards, :messages,
:attachments :attachments,
:enumerations
def setup def setup
super super
@ -150,6 +151,8 @@ RAW
message_url = {:controller => 'messages', :action => 'show', :board_id => 1, :id => 4} message_url = {:controller => 'messages', :action => 'show', :board_id => 1, :id => 4}
project_url = {:controller => 'projects', :action => 'show', :id => 'subproject1'}
source_url = {:controller => 'repositories', :action => 'entry', :id => 'ecookbook', :path => ['some', 'file']} source_url = {:controller => 'repositories', :action => 'entry', :id => 'ecookbook', :path => ['some', 'file']}
source_url_with_ext = {:controller => 'repositories', :action => 'entry', :id => 'ecookbook', :path => ['some', 'file.ext']} source_url_with_ext = {:controller => 'repositories', :action => 'entry', :id => 'ecookbook', :path => ['some', 'file.ext']}
@ -184,6 +187,10 @@ RAW
# message # message
'message#4' => link_to('Post 2', message_url, :class => 'message'), 'message#4' => link_to('Post 2', message_url, :class => 'message'),
'message#5' => link_to('RE: post 2', message_url.merge(:anchor => 'message-5'), :class => 'message'), 'message#5' => link_to('RE: post 2', message_url.merge(:anchor => 'message-5'), :class => 'message'),
# project
'project#3' => link_to('eCookbook Subproject 1', project_url, :class => 'project'),
'project:subproject1' => 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.',
'!r1' => 'r1', '!r1' => 'r1',
@ -199,7 +206,7 @@ RAW
"http://foo.bar/FAQ#3" => '<a class="external" href="http://foo.bar/FAQ#3">http://foo.bar/FAQ#3</a>', "http://foo.bar/FAQ#3" => '<a class="external" href="http://foo.bar/FAQ#3">http://foo.bar/FAQ#3</a>',
} }
@project = Project.find(1) @project = Project.find(1)
to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text) } to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text), "#{text} failed" }
end end
def test_wiki_links def test_wiki_links