##// END OF EJS Templates
Use local links in wiki pages when possible (#3276)....
Etienne Massip -
r7438:1ee65e046913
parent child
Show More
@@ -572,13 +572,17 module ApplicationHelper
572 572 end
573 573 # check if page exists
574 574 wiki_page = link_project.wiki.find_page(page)
575 url = case options[:wiki_links]
575 url = if anchor.present? && wiki_page.present? && (obj.is_a?(WikiContent) || obj.is_a?(WikiContent::Version)) && obj.page == wiki_page
576 "##{anchor}"
577 else
578 case options[:wiki_links]
576 579 when :local; "#{title}.html"
577 580 when :anchor; "##{title}" # used for single-file wiki export
578 581 else
579 582 wiki_page_id = page.present? ? Wiki.titleize(page) : nil
580 583 url_for(:only_path => only_path, :controller => 'wiki', :action => 'show', :project_id => link_project, :id => wiki_page_id, :anchor => anchor)
581 584 end
585 end
582 586 link_to(h(title || page), url, :class => ('wiki-page' + (wiki_page ? '' : ' new')))
583 587 else
584 588 # project or wiki doesn't exist
@@ -533,6 +533,33 EXPECTED
533 533 assert_equal expected, textilizable(raw)
534 534 end
535 535
536 def test_wiki_links_within_wiki_page_context
537
538 page = WikiPage.find_by_title('Another_page' )
539
540 to_test = {
541 # link to another page
542 '[[CookBook documentation]]' => '<a href="/projects/ecookbook/wiki/CookBook_documentation" class="wiki-page">CookBook documentation</a>',
543 '[[CookBook documentation|documentation]]' => '<a href="/projects/ecookbook/wiki/CookBook_documentation" class="wiki-page">documentation</a>',
544 '[[CookBook documentation#One-section]]' => '<a href="/projects/ecookbook/wiki/CookBook_documentation#One-section" class="wiki-page">CookBook documentation</a>',
545 '[[CookBook documentation#One-section|documentation]]' => '<a href="/projects/ecookbook/wiki/CookBook_documentation#One-section" class="wiki-page">documentation</a>',
546 # link to the current page
547 '[[Another page]]' => '<a href="/projects/ecookbook/wiki/Another_page" class="wiki-page">Another page</a>',
548 '[[Another page|Page]]' => '<a href="/projects/ecookbook/wiki/Another_page" class="wiki-page">Page</a>',
549 '[[Another page#anchor]]' => '<a href="#anchor" class="wiki-page">Another page</a>',
550 '[[Another page#anchor|Page]]' => '<a href="#anchor" class="wiki-page">Page</a>',
551 # page that doesn't exist
552 '[[Unknown page]]' => '<a href="/projects/ecookbook/wiki/Unknown_page" class="wiki-page new">Unknown page</a>',
553 '[[Unknown page|404]]' => '<a href="/projects/ecookbook/wiki/Unknown_page" class="wiki-page new">404</a>',
554 '[[Unknown page#anchor]]' => '<a href="/projects/ecookbook/wiki/Unknown_page#anchor" class="wiki-page new">Unknown page</a>',
555 '[[Unknown page#anchor|404]]' => '<a href="/projects/ecookbook/wiki/Unknown_page#anchor" class="wiki-page new">404</a>',
556 }
557
558 @project = Project.find(1)
559
560 to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(WikiContent.generate!( :text => text, :page => page ), :text) }
561 end
562
536 563 def test_table_of_content
537 564 raw = <<-RAW
538 565 {{toc}}
General Comments 0
You need to be logged in to leave comments. Login now