@@ -588,16 +588,25 module ApplicationHelper | |||
|
588 | 588 | # source:some/file#L120 -> Link to line 120 of the file |
|
589 | 589 | # source:some/file@52#L120 -> Link to line 120 of the file's revision 52 |
|
590 | 590 | # export:some/file -> Force the download of the file |
|
591 | # Forum messages: | |
|
591 | # Forum messages: | |
|
592 | 592 | # message#1218 -> Link to message with id 1218 |
|
593 | # | |
|
594 | # Links can refer other objects from other projects, using project identifier: | |
|
595 | # identifier:r52 | |
|
596 | # identifier:document:"Some document" | |
|
597 | # identifier:version:1.0.0 | |
|
598 | # identifier:source:some/file | |
|
593 | 599 | def parse_redmine_links(text, project, obj, attr, only_path, options) |
|
594 | text.gsub!(%r{([\s\(,\-\[\>]|^)(!)?(attachment|document|version|commit|source|export|message|project)?((#|r)(\d+)|(:)([^"\s<>][^\s<>]*?|"[^"]+?"))(?=(?=[[:punct:]]\W)|,|\s|\]|<|$)}) do |m| | |
|
595 |
leading, esc, prefix, sep, identifier = $1, $2, $3, $5 || $ |
|
|
600 | text.gsub!(%r{([\s\(,\-\[\>]|^)(!)?(([a-z0-9\-]+):)?(attachment|document|version|commit|source|export|message|project)?((#|r)(\d+)|(:)([^"\s<>][^\s<>]*?|"[^"]+?"))(?=(?=[[:punct:]]\W)|,|\s|\]|<|$)}) do |m| | |
|
601 | leading, esc, project_prefix, project_identifier, prefix, sep, identifier = $1, $2, $3, $4, $5, $7 || $9, $8 || $10 | |
|
596 | 602 | link = nil |
|
603 | if project_identifier | |
|
604 | project = Project.visible.find_by_identifier(project_identifier) | |
|
605 | end | |
|
597 | 606 | if esc.nil? |
|
598 | 607 | if prefix.nil? && sep == 'r' |
|
599 | 608 | if project && (changeset = project.changesets.find_by_revision(identifier)) |
|
600 | link = link_to("r#{identifier}", {:only_path => only_path, :controller => 'repositories', :action => 'revision', :id => project, :rev => changeset.revision}, | |
|
609 | link = link_to("#{project_prefix}r#{identifier}", {:only_path => only_path, :controller => 'repositories', :action => 'revision', :id => project, :rev => changeset.revision}, | |
|
601 | 610 | :class => 'changeset', |
|
602 | 611 | :title => truncate_single_line(changeset.comments, :length => 100)) |
|
603 | 612 | end |
@@ -651,7 +660,7 module ApplicationHelper | |||
|
651 | 660 | end |
|
652 | 661 | when 'commit' |
|
653 | 662 | if project && (changeset = project.changesets.find(:first, :conditions => ["scmid LIKE ?", "#{name}%"])) |
|
654 | link = link_to h("#{name}"), {:only_path => only_path, :controller => 'repositories', :action => 'revision', :id => project, :rev => changeset.identifier}, | |
|
663 | link = link_to h("#{project_prefix}#{name}"), {:only_path => only_path, :controller => 'repositories', :action => 'revision', :id => project, :rev => changeset.identifier}, | |
|
655 | 664 | :class => 'changeset', |
|
656 | 665 | :title => truncate_single_line(changeset.comments, :length => 100) |
|
657 | 666 | end |
@@ -659,7 +668,7 module ApplicationHelper | |||
|
659 | 668 | if project && project.repository |
|
660 | 669 | name =~ %r{^[/\\]*(.*?)(@([0-9a-f]+))?(#(L\d+))?$} |
|
661 | 670 | path, rev, anchor = $1, $3, $5 |
|
662 | link = link_to h("#{prefix}:#{name}"), {:controller => 'repositories', :action => 'entry', :id => project, | |
|
671 | link = link_to h("#{project_prefix}#{prefix}:#{name}"), {:controller => 'repositories', :action => 'entry', :id => project, | |
|
663 | 672 | :path => to_path_param(path), |
|
664 | 673 | :rev => rev, |
|
665 | 674 | :anchor => anchor, |
@@ -679,7 +688,7 module ApplicationHelper | |||
|
679 | 688 | end |
|
680 | 689 | end |
|
681 | 690 | end |
|
682 | leading + (link || "#{prefix}#{sep}#{identifier}") | |
|
691 | leading + (link || "#{project_prefix}#{prefix}#{sep}#{identifier}") | |
|
683 | 692 | end |
|
684 | 693 | end |
|
685 | 694 |
@@ -46,7 +46,9 | |||
|
46 | 46 | <ul> |
|
47 | 47 | <li>Link to an issue: <strong>#124</strong> (displays <del><a href="#" class="issue" title="bulk edit doesn't change the category or fixed version properties (Closed)">#124</a></del>, link is striked-through if the issue is closed)</li> |
|
48 | 48 | <li>Link to a changeset: <strong>r758</strong> (displays <a href="#" class="changeset" title="Search engine now only searches objects the user is allowed to view.">r758</a>)</li> |
|
49 |
<li>Link to a changeset with a non-numeric hash: <strong>commit:c6f4d0fd</strong> (displays |
|
|
49 | <li>Link to a changeset with a non-numeric hash: <strong>commit:c6f4d0fd</strong> (displays <a href="#" class="changeset">c6f4d0fd</a>).</li> | |
|
50 | <li>Link to a changeset of another project: <strong>sandbox:r758</strong> (displays <a href="#" class="changeset" title="Search engine now only searches objects the user is allowed to view.">sanbox:r758</a>)</li> | |
|
51 | <li>Link to a changeset with a non-numeric hash: <strong>sandbox:c6f4d0fd</strong> (displays <a href="#" class="changeset">sandbox:c6f4d0fd</a>).</li> | |
|
50 | 52 | </ul> |
|
51 | 53 | |
|
52 | 54 | <p>Wiki links:</p> |
@@ -74,7 +76,7 | |||
|
74 | 76 | <li><strong>document#17</strong> (link to document with id 17)</li> |
|
75 | 77 | <li><strong>document:Greetings</strong> (link to the document with title "Greetings")</li> |
|
76 | 78 | <li><strong>document:"Some document"</strong> (double quotes can be used when document title contains spaces)</li> |
|
77 |
<li><strong>documen |
|
|
79 | <li><strong>sandbox:document:"Some document"</strong> (link to a document with title "Some document" in other project "sandbox")</li> | |
|
78 | 80 | </ul></li> |
|
79 | 81 | </ul> |
|
80 | 82 | |
@@ -84,6 +86,7 | |||
|
84 | 86 | <li><strong>version#3</strong> (link to version with id 3)</li> |
|
85 | 87 | <li><strong>version:1.0.0</strong> (link to version named "1.0.0")</li> |
|
86 | 88 | <li><strong>version:"1.0 beta 2"</strong></li> |
|
89 | <li><strong>sandbox:version:1.0.0</strong> (link to version "1.0.0" in the project "sandbox")</li> | |
|
87 | 90 | </ul></li> |
|
88 | 91 | </ul> |
|
89 | 92 | |
@@ -103,7 +106,9 | |||
|
103 | 106 | <li><strong>source:some/file#L120</strong> (link to line 120 of the file)</li> |
|
104 | 107 | <li><strong>source:some/file@52#L120</strong> (link to line 120 of the file's revision 52)</li> |
|
105 | 108 | <li><strong>source:"some file@52#L120"</strong> (use double quotes when the URL contains spaces</li> |
|
106 | <li><strong>export:some/file</strong> (force the download of the file)</li> | |
|
109 | <li><strong>export:some/file</strong> (force the download of the file)</li> | |
|
110 | <li><strong>sandbox:source:some/file</strong> (link to the file located at /some/file in the repository of the project "sandbox")</li> | |
|
111 | <li><strong>sandbox:export:some/file</strong> (force the download of the file)</li> | |
|
107 | 112 | </ul></li> |
|
108 | 113 | </ul> |
|
109 | 114 |
@@ -224,6 +224,35 RAW | |||
|
224 | 224 | @project = Project.find(1) |
|
225 | 225 | to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text), "#{text} failed" } |
|
226 | 226 | end |
|
227 | ||
|
228 | def test_cross_project_redmine_links | |
|
229 | source_link = link_to('ecookbook:source:/some/file', {:controller => 'repositories', :action => 'entry', :id => 'ecookbook', :path => ['some', 'file']}, | |
|
230 | :class => 'source') | |
|
231 | ||
|
232 | changeset_link = link_to('ecookbook:r2', {:controller => 'repositories', :action => 'revision', :id => 'ecookbook', :rev => 2}, | |
|
233 | :class => 'changeset', :title => 'This commit fixes #1, #2 and references #1 & #3') | |
|
234 | ||
|
235 | to_test = { | |
|
236 | # documents | |
|
237 | 'document:"Test document"' => 'document:"Test document"', | |
|
238 | 'ecookbook:document:"Test document"' => '<a href="/documents/1" class="document">Test document</a>', | |
|
239 | 'invalid:document:"Test document"' => 'invalid:document:"Test document"', | |
|
240 | # versions | |
|
241 | 'version:"1.0"' => 'version:"1.0"', | |
|
242 | 'ecookbook:version:"1.0"' => '<a href="/versions/show/2" class="version">1.0</a>', | |
|
243 | 'invalid:version:"1.0"' => 'invalid:version:"1.0"', | |
|
244 | # changeset | |
|
245 | 'r2' => 'r2', | |
|
246 | 'ecookbook:r2' => changeset_link, | |
|
247 | 'invalid:r2' => 'invalid:r2', | |
|
248 | # source | |
|
249 | 'source:/some/file' => 'source:/some/file', | |
|
250 | 'ecookbook:source:/some/file' => source_link, | |
|
251 | 'invalid:source:/some/file' => 'invalid:source:/some/file', | |
|
252 | } | |
|
253 | @project = Project.find(3) | |
|
254 | to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text), "#{text} failed" } | |
|
255 | end | |
|
227 | 256 | |
|
228 | 257 | def test_redmine_links_git_commit |
|
229 | 258 | changeset_link = link_to('abcd', |
General Comments 0
You need to be logged in to leave comments.
Login now