From 3168ee3d47f53f6045a039acd1d0febfbd356787 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Lang Date: Sat, 13 Feb 2010 10:32:06 +0000 Subject: [PATCH] Adds projects links (#4812). git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@3422 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- app/helpers/application_helper.rb | 12 +++++++++++- test/unit/helpers/application_helper_test.rb | 11 +++++++++-- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index fd7d821d..ac1153dd 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -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 diff --git a/test/unit/helpers/application_helper_test.rb b/test/unit/helpers/application_helper_test.rb index 2f7c6fde..11abc473 100644 --- a/test/unit/helpers/application_helper_test.rb +++ b/test/unit/helpers/application_helper_test.rb @@ -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" => 'http://foo.bar/FAQ#3', } @project = Project.find(1) - to_test.each { |text, result| assert_equal "

#{result}

", textilizable(text) } + to_test.each { |text, result| assert_equal "

#{result}

", textilizable(text), "#{text} failed" } end def test_wiki_links -- 2.11.0