From: Vadim Pushtaev Date: Thu, 14 Nov 2013 11:16:05 +0400 Subject: refs #12981 (redmine.org) - Wiki self-link with anchor looks strange in "preview" section --- app/helpers/application_helper.rb | 16 +++++++------- app/views/common/_preview.html.erb | 2 +- test/unit/helpers/application_helper_test.rb | 29 ++++++++++++++++++++++++++ 3 files changed, 39 insertions(+), 8 deletions(-) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 2b37ad3..796e2cc 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -630,18 +630,20 @@ module ApplicationHelper anchor = sanitize_anchor_name(anchor) if anchor.present? # check if page exists wiki_page = link_project.wiki.find_page(page) - url = if anchor.present? && wiki_page.present? && (obj.is_a?(WikiContent) || obj.is_a?(WikiContent::Version)) && obj.page == wiki_page - "##{anchor}" - else - case options[:wiki_links] - when :local; "#{page.present? ? Wiki.titleize(page) : ''}.html" + (anchor.present? ? "##{anchor}" : '') - when :anchor; "##{page.present? ? Wiki.titleize(page) : title}" + (anchor.present? ? "_#{anchor}" : '') # used for single-file wiki export + wiki_links = options[:wiki_links] + url = case + when wiki_links != :full && anchor.present? && wiki_page.present? && + (obj.is_a?(WikiContent) || obj.is_a?(WikiContent::Version)) && obj.page == wiki_page + "##{anchor}" + when wiki_links == :local + "#{page.present? ? Wiki.titleize(page) : ''}.html" + (anchor.present? ? "##{anchor}" : '') + when wiki_links == :anchor + "##{page.present? ? Wiki.titleize(page) : title}" + (anchor.present? ? "_#{anchor}" : '') # used for single-file wiki export else wiki_page_id = page.present? ? Wiki.titleize(page) : nil parent = wiki_page.nil? && obj.is_a?(WikiContent) && obj.page && project == link_project ? obj.page.title : nil url_for(:only_path => only_path, :controller => 'wiki', :action => 'show', :project_id => link_project, :id => wiki_page_id, :version => nil, :anchor => anchor, :parent => parent) - end end link_to(title.present? ? title.html_safe : h(page), url, :class => ('wiki-page' + (wiki_page ? '' : ' new'))) else diff --git a/app/views/common/_preview.html.erb b/app/views/common/_preview.html.erb index 90d83ce..99f2762 100644 --- a/app/views/common/_preview.html.erb +++ b/app/views/common/_preview.html.erb @@ -1,3 +1,3 @@
<%= l(:label_preview) %> -<%= textilizable @text, :attachments => @attachments, :object => @previewed %> +<%= textilizable @text, :attachments => @attachments, :object => @previewed, :wiki_links => :full %>
diff --git a/test/unit/helpers/application_helper_test.rb b/test/unit/helpers/application_helper_test.rb index 0d2cc44..c8cdf2d 100644 --- a/test/unit/helpers/application_helper_test.rb +++ b/test/unit/helpers/application_helper_test.rb @@ -678,6 +678,35 @@ RAW to_test.each { |text, result| assert_equal "

#{result}

", textilizable(WikiContent.new( :text => text, :page => page ), :text) } end + def test_wiki_links_within_wiki_page_context_with_wiki_links_full_param + + page = WikiPage.find_by_title('Another_page' ) + + to_test = { + # link to another page + '[[CookBook documentation]]' => 'CookBook documentation', + '[[CookBook documentation|documentation]]' => 'documentation', + '[[CookBook documentation#One-section]]' => 'CookBook documentation', + '[[CookBook documentation#One-section|documentation]]' => 'documentation', + # link to the current page + '[[Another page]]' => 'Another page', + '[[Another page|Page]]' => 'Page', + '[[Another page#anchor]]' => 'Another page', + '[[Another page#anchor|Page]]' => 'Page', + # page that doesn't exist + '[[Unknown page]]' => 'Unknown page', + '[[Unknown page|404]]' => '404', + '[[Unknown page#anchor]]' => 'Unknown page', + '[[Unknown page#anchor|404]]' => '404', + } + + @project = Project.find(1) + + to_test.each { |text, result| + assert_equal "

#{result}

", textilizable(WikiContent.new( :text => text, :page => page ), :text, :wiki_links=> :full ) + } + end + def test_wiki_links_anchor_option_should_prepend_page_title_to_href to_test = { -- 1.7.10.4