##// END OF EJS Templates
Adds links to forum messages using message#id syntax (#1756)....
Jean-Philippe Lang -
r1728:16509203398f
parent child
Show More
@@ -319,7 +319,9 module ApplicationHelper
319 # source:some/file#L120 -> Link to line 120 of the file
319 # source:some/file#L120 -> Link to line 120 of the file
320 # source:some/file@52#L120 -> Link to line 120 of the file's revision 52
320 # source:some/file@52#L120 -> Link to line 120 of the file's revision 52
321 # export:some/file -> Force the download of the file
321 # export:some/file -> Force the download of the file
322 text = text.gsub(%r{([\s\(,\-\>]|^)(!)?(attachment|document|version|commit|source|export)?((#|r)(\d+)|(:)([^"\s<>][^\s<>]*?|"[^"]+?"))(?=(?=[[:punct:]]\W)|\s|<|$)}) do |m|
322 # Forum messages:
323 # message#1218 -> Link to message with id 1218
324 text = text.gsub(%r{([\s\(,\-\>]|^)(!)?(attachment|document|version|commit|source|export|message)?((#|r)(\d+)|(:)([^"\s<>][^\s<>]*?|"[^"]+?"))(?=(?=[[:punct:]]\W)|\s|<|$)}) do |m|
323 leading, esc, prefix, sep, oid = $1, $2, $3, $5 || $7, $6 || $8
325 leading, esc, prefix, sep, oid = $1, $2, $3, $5 || $7, $6 || $8
324 link = nil
326 link = nil
325 if esc.nil?
327 if esc.nil?
@@ -349,6 +351,16 module ApplicationHelper
349 link = link_to h(version.name), {:only_path => only_path, :controller => 'versions', :action => 'show', :id => version},
351 link = link_to h(version.name), {:only_path => only_path, :controller => 'versions', :action => 'show', :id => version},
350 :class => 'version'
352 :class => 'version'
351 end
353 end
354 when 'message'
355 if message = Message.find_by_id(oid, :include => [:parent, {:board => :project}], :conditions => Project.visible_by(User.current))
356 link = link_to h(truncate(message.subject, 60)), {:only_path => only_path,
357 :controller => 'messages',
358 :action => 'show',
359 :board_id => message.board,
360 :id => message.root,
361 :anchor => (message.parent ? "message-#{message.id}" : nil)},
362 :class => 'message'
363 end
352 end
364 end
353 elsif sep == ':'
365 elsif sep == ':'
354 # removes the double quotes if any
366 # removes the double quotes if any
@@ -20,7 +20,11 require File.dirname(__FILE__) + '/../../test_helper'
20 class ApplicationHelperTest < HelperTestCase
20 class ApplicationHelperTest < HelperTestCase
21 include ApplicationHelper
21 include ApplicationHelper
22 include ActionView::Helpers::TextHelper
22 include ActionView::Helpers::TextHelper
23 fixtures :projects, :repositories, :changesets, :trackers, :issue_statuses, :issues, :documents, :versions, :wikis, :wiki_pages, :wiki_contents, :roles, :enabled_modules
23 fixtures :projects, :roles, :enabled_modules,
24 :repositories, :changesets,
25 :trackers, :issue_statuses, :issues, :versions, :documents,
26 :wikis, :wiki_pages, :wiki_contents,
27 :boards, :messages
24
28
25 def setup
29 def setup
26 super
30 super
@@ -83,6 +87,8 class ApplicationHelperTest < HelperTestCase
83 version_link = link_to('1.0', {:controller => 'versions', :action => 'show', :id => 2},
87 version_link = link_to('1.0', {:controller => 'versions', :action => 'show', :id => 2},
84 :class => 'version')
88 :class => 'version')
85
89
90 message_url = {:controller => 'messages', :action => 'show', :board_id => 1, :id => 4}
91
86 source_url = {:controller => 'repositories', :action => 'entry', :id => 'ecookbook', :path => ['some', 'file']}
92 source_url = {:controller => 'repositories', :action => 'entry', :id => 'ecookbook', :path => ['some', 'file']}
87 source_url_with_ext = {:controller => 'repositories', :action => 'entry', :id => 'ecookbook', :path => ['some', 'file.ext']}
93 source_url_with_ext = {:controller => 'repositories', :action => 'entry', :id => 'ecookbook', :path => ['some', 'file.ext']}
88
94
@@ -111,6 +117,9 class ApplicationHelperTest < HelperTestCase
111 'source:/some/file.ext#L110' => link_to('source:/some/file.ext#L110', source_url_with_ext.merge(:anchor => 'L110'), :class => 'source'),
117 'source:/some/file.ext#L110' => link_to('source:/some/file.ext#L110', source_url_with_ext.merge(:anchor => 'L110'), :class => 'source'),
112 'source:/some/file@52#L110' => link_to('source:/some/file@52#L110', source_url.merge(:rev => 52, :anchor => 'L110'), :class => 'source'),
118 'source:/some/file@52#L110' => link_to('source:/some/file@52#L110', source_url.merge(:rev => 52, :anchor => 'L110'), :class => 'source'),
113 'export:/some/file' => link_to('export:/some/file', source_url.merge(:format => 'raw'), :class => 'source download'),
119 'export:/some/file' => link_to('export:/some/file', source_url.merge(:format => 'raw'), :class => 'source download'),
120 # message
121 'message#4' => link_to('Post 2', message_url, :class => 'message'),
122 'message#5' => link_to('RE: post 2', message_url.merge(:anchor => 'message-5'), :class => 'message'),
114 # escaping
123 # escaping
115 '!#3.' => '#3.',
124 '!#3.' => '#3.',
116 '!r1' => 'r1',
125 '!r1' => 'r1',
General Comments 0
You need to be logged in to leave comments. Login now