Commit 3168ee3d authored by Jean-Philippe Lang's avatar Jean-Philippe Lang

Adds projects links (#4812).

git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@3422 e93f8b46-1217-0410-a6f0-8f06a7374b81
parent 89b97000
......@@ -510,7 +510,7 @@ 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|
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
link = nil
if esc.nil?
......@@ -549,6 +549,11 @@ module ApplicationHelper
:anchor => (message.parent ? "message-#{message.id}" : nil)},
:class => 'message'
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
elsif sep == ':'
# 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},
:class => 'attachment'
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
......
......@@ -27,7 +27,8 @@ class ApplicationHelperTest < HelperTestCase
:trackers, :issue_statuses, :issues, :versions, :documents,
:wikis, :wiki_pages, :wiki_contents,
:boards, :messages,
:attachments
:attachments,
:enumerations
def setup
super
......@@ -150,6 +151,8 @@ RAW
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_with_ext = {:controller => 'repositories', :action => 'entry', :id => 'ecookbook', :path => ['some', 'file.ext']}
......@@ -184,6 +187,10 @@ RAW
# 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'),
# 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
'!#3.' => '#3.',
'!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>',
}
@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
def test_wiki_links
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment