@@ -246,12 +246,12 module ApplicationHelper | |||||
246 | case options[:wiki_links] |
|
246 | case options[:wiki_links] | |
247 | when :local |
|
247 | when :local | |
248 | # used for local links to html files |
|
248 | # used for local links to html files | |
249 | format_wiki_link = Proc.new {|project, title| "#{title}.html" } |
|
249 | format_wiki_link = Proc.new {|project, title, anchor| "#{title}.html" } | |
250 | when :anchor |
|
250 | when :anchor | |
251 | # used for single-file wiki export |
|
251 | # used for single-file wiki export | |
252 | format_wiki_link = Proc.new {|project, title| "##{title}" } |
|
252 | format_wiki_link = Proc.new {|project, title, anchor| "##{title}" } | |
253 | else |
|
253 | else | |
254 | format_wiki_link = Proc.new {|project, title| url_for(:only_path => only_path, :controller => 'wiki', :action => 'index', :id => project, :page => title) } |
|
254 | format_wiki_link = Proc.new {|project, title, anchor| url_for(:only_path => only_path, :controller => 'wiki', :action => 'index', :id => project, :page => title, :anchor => anchor) } | |
255 | end |
|
255 | end | |
256 |
|
256 | |||
257 | project = options[:project] || @project || (obj && obj.respond_to?(:project) ? obj.project : nil) |
|
257 | project = options[:project] || @project || (obj && obj.respond_to?(:project) ? obj.project : nil) | |
@@ -277,9 +277,14 module ApplicationHelper | |||||
277 | end |
|
277 | end | |
278 |
|
278 | |||
279 | if link_project && link_project.wiki |
|
279 | if link_project && link_project.wiki | |
|
280 | # extract anchor | |||
|
281 | anchor = nil | |||
|
282 | if page =~ /^(.+?)\#(.+)$/ | |||
|
283 | page, anchor = $1, $2 | |||
|
284 | end | |||
280 | # check if page exists |
|
285 | # check if page exists | |
281 | wiki_page = link_project.wiki.find_page(page) |
|
286 | wiki_page = link_project.wiki.find_page(page) | |
282 | link_to((title || page), format_wiki_link.call(link_project, Wiki.titleize(page)), |
|
287 | link_to((title || page), format_wiki_link.call(link_project, Wiki.titleize(page), anchor), | |
283 | :class => ('wiki-page' + (wiki_page ? '' : ' new'))) |
|
288 | :class => ('wiki-page' + (wiki_page ? '' : ' new'))) | |
284 | else |
|
289 | else | |
285 | # project or wiki doesn't exist |
|
290 | # project or wiki doesn't exist |
@@ -133,6 +133,9 class ApplicationHelperTest < HelperTestCase | |||||
133 | to_test = { |
|
133 | to_test = { | |
134 | '[[CookBook documentation]]' => '<a href="/wiki/ecookbook/CookBook_documentation" class="wiki-page">CookBook documentation</a>', |
|
134 | '[[CookBook documentation]]' => '<a href="/wiki/ecookbook/CookBook_documentation" class="wiki-page">CookBook documentation</a>', | |
135 | '[[Another page|Page]]' => '<a href="/wiki/ecookbook/Another_page" class="wiki-page">Page</a>', |
|
135 | '[[Another page|Page]]' => '<a href="/wiki/ecookbook/Another_page" class="wiki-page">Page</a>', | |
|
136 | # link with anchor | |||
|
137 | '[[CookBook documentation#One-section]]' => '<a href="/wiki/ecookbook/CookBook_documentation#One-section" class="wiki-page">CookBook documentation</a>', | |||
|
138 | '[[Another page#anchor|Page]]' => '<a href="/wiki/ecookbook/Another_page#anchor" class="wiki-page">Page</a>', | |||
136 | # page that doesn't exist |
|
139 | # page that doesn't exist | |
137 | '[[Unknown page]]' => '<a href="/wiki/ecookbook/Unknown_page" class="wiki-page new">Unknown page</a>', |
|
140 | '[[Unknown page]]' => '<a href="/wiki/ecookbook/Unknown_page" class="wiki-page new">Unknown page</a>', | |
138 | '[[Unknown page|404]]' => '<a href="/wiki/ecookbook/Unknown_page" class="wiki-page new">404</a>', |
|
141 | '[[Unknown page|404]]' => '<a href="/wiki/ecookbook/Unknown_page" class="wiki-page new">404</a>', |
General Comments 0
You need to be logged in to leave comments.
Login now