]> source.dussan.org Git - redmine.git/commitdiff
Adds support for wiki links with anchor (#1647).
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Mon, 28 Jul 2008 17:20:31 +0000 (17:20 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Mon, 28 Jul 2008 17:20:31 +0000 (17:20 +0000)
git-svn-id: http://redmine.rubyforge.org/svn/trunk@1706 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/helpers/application_helper.rb
test/unit/helpers/application_helper_test.rb

index 6d6eb9107627a000942edc502acf911b330b41b5..a4102c84a9f05634664f0c5bfa2b51165edaa7d3 100644 (file)
@@ -246,12 +246,12 @@ module ApplicationHelper
     case options[:wiki_links]
     when :local
       # used for local links to html files
-      format_wiki_link = Proc.new {|project, title| "#{title}.html" }
+      format_wiki_link = Proc.new {|project, title, anchor| "#{title}.html" }
     when :anchor
       # used for single-file wiki export
-      format_wiki_link = Proc.new {|project, title| "##{title}" }
+      format_wiki_link = Proc.new {|project, title, anchor| "##{title}" }
     else
-      format_wiki_link = Proc.new {|project, title| url_for(:only_path => only_path, :controller => 'wiki', :action => 'index', :id => project, :page => title) }
+      format_wiki_link = Proc.new {|project, title, anchor| url_for(:only_path => only_path, :controller => 'wiki', :action => 'index', :id => project, :page => title, :anchor => anchor) }
     end
     
     project = options[:project] || @project || (obj && obj.respond_to?(:project) ? obj.project : nil)
@@ -277,9 +277,14 @@ module ApplicationHelper
         end
         
         if link_project && link_project.wiki
+          # extract anchor
+          anchor = nil
+          if page =~ /^(.+?)\#(.+)$/
+            page, anchor = $1, $2
+          end
           # check if page exists
           wiki_page = link_project.wiki.find_page(page)
-          link_to((title || page), format_wiki_link.call(link_project, Wiki.titleize(page)),
+          link_to((title || page), format_wiki_link.call(link_project, Wiki.titleize(page), anchor),
                                    :class => ('wiki-page' + (wiki_page ? '' : ' new')))
         else
           # project or wiki doesn't exist
index 71ef572b0e63e5b030abbeaeae4e809e48e91789..979321bd3646f55bd57518e754bfdc6652548e0a 100644 (file)
@@ -133,6 +133,9 @@ class ApplicationHelperTest < HelperTestCase
     to_test = {
       '[[CookBook documentation]]' => '<a href="/wiki/ecookbook/CookBook_documentation" class="wiki-page">CookBook documentation</a>',
       '[[Another page|Page]]' => '<a href="/wiki/ecookbook/Another_page" class="wiki-page">Page</a>',
+      # link with anchor
+      '[[CookBook documentation#One-section]]' => '<a href="/wiki/ecookbook/CookBook_documentation#One-section" class="wiki-page">CookBook documentation</a>',
+      '[[Another page#anchor|Page]]' => '<a href="/wiki/ecookbook/Another_page#anchor" class="wiki-page">Page</a>',
       # page that doesn't exist
       '[[Unknown page]]' => '<a href="/wiki/ecookbook/Unknown_page" class="wiki-page new">Unknown page</a>',
       '[[Unknown page|404]]' => '<a href="/wiki/ecookbook/Unknown_page" class="wiki-page new">404</a>',