Defect #12981 ยป 12981.diff
| app/helpers/application_helper.rb | ||
|---|---|---|
|
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
|
||
| app/views/common/_preview.html.erb | ||
|---|---|---|
|
<fieldset class="preview"><legend><%= l(:label_preview) %></legend>
|
||
|
<%= textilizable @text, :attachments => @attachments, :object => @previewed %>
|
||
|
<%= textilizable @text, :attachments => @attachments, :object => @previewed, :wiki_links => :full %>
|
||
|
</fieldset>
|
||
| test/unit/helpers/application_helper_test.rb | ||
|---|---|---|
|
to_test.each { |text, result| assert_equal "<p>#{result}</p>", 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]]' => '<a href="/projects/ecookbook/wiki/CookBook_documentation" class="wiki-page">CookBook documentation</a>',
|
||
|
'[[CookBook documentation|documentation]]' => '<a href="/projects/ecookbook/wiki/CookBook_documentation" class="wiki-page">documentation</a>',
|
||
|
'[[CookBook documentation#One-section]]' => '<a href="/projects/ecookbook/wiki/CookBook_documentation#One-section" class="wiki-page">CookBook documentation</a>',
|
||
|
'[[CookBook documentation#One-section|documentation]]' => '<a href="/projects/ecookbook/wiki/CookBook_documentation#One-section" class="wiki-page">documentation</a>',
|
||
|
# link to the current page
|
||
|
'[[Another page]]' => '<a href="/projects/ecookbook/wiki/Another_page" class="wiki-page">Another page</a>',
|
||
|
'[[Another page|Page]]' => '<a href="/projects/ecookbook/wiki/Another_page" class="wiki-page">Page</a>',
|
||
|
'[[Another page#anchor]]' => '<a href="/projects/ecookbook/wiki/Another_page#anchor" class="wiki-page">Another page</a>',
|
||
|
'[[Another page#anchor|Page]]' => '<a href="/projects/ecookbook/wiki/Another_page#anchor" class="wiki-page">Page</a>',
|
||
|
# page that doesn't exist
|
||
|
'[[Unknown page]]' => '<a href="/projects/ecookbook/wiki/Unknown_page?parent=Another_page" class="wiki-page new">Unknown page</a>',
|
||
|
'[[Unknown page|404]]' => '<a href="/projects/ecookbook/wiki/Unknown_page?parent=Another_page" class="wiki-page new">404</a>',
|
||
|
'[[Unknown page#anchor]]' => '<a href="/projects/ecookbook/wiki/Unknown_page?parent=Another_page#anchor" class="wiki-page new">Unknown page</a>',
|
||
|
'[[Unknown page#anchor|404]]' => '<a href="/projects/ecookbook/wiki/Unknown_page?parent=Another_page#anchor" class="wiki-page new">404</a>',
|
||
|
}
|
||
|
@project = Project.find(1)
|
||
|
to_test.each { |text, result|
|
||
|
assert_equal "<p>#{result}</p>", 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 = {
|
||