Fixes #248
This commit is contained in:
parent
839dc364dd
commit
4b29a843e5
|
@ -15,12 +15,13 @@ class Include < WikiChunk::WikiReference
|
|||
def initialize(match_data, content)
|
||||
super
|
||||
@page_name = match_data[1].strip
|
||||
@unmask_text = get_unmask_text_avoiding_recursion_loops
|
||||
rendering_mode = content.options[:mode] || :show
|
||||
@unmask_text = get_unmask_text_avoiding_recursion_loops(rendering_mode)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def get_unmask_text_avoiding_recursion_loops
|
||||
def get_unmask_text_avoiding_recursion_loops(rendering_mode)
|
||||
if refpage
|
||||
# TODO This way of instantiating a renderer is ugly.
|
||||
renderer = PageRenderer.new(refpage.current_revision)
|
||||
|
@ -30,7 +31,13 @@ class Include < WikiChunk::WikiReference
|
|||
return "<em>Recursive include detected; #{@page_name} --> #{@content.page_name} " +
|
||||
"--> #{@page_name}</em>\n"
|
||||
else
|
||||
included_content = renderer.display_content
|
||||
included_content =
|
||||
case rendering_mode
|
||||
when :show then renderer.display_content
|
||||
when :publish then renderer.display_published
|
||||
when :export then renderer.display_content_for_export
|
||||
else raise "Unsupported rendering mode #{@mode.inspect}"
|
||||
end
|
||||
@content.merge_chunks(included_content)
|
||||
return included_content.pre_rendered
|
||||
end
|
||||
|
|
|
@ -356,6 +356,18 @@ class PageRendererTest < Test::Unit::TestCase
|
|||
assert_equal WikiReference::CATEGORY, references[0].link_type
|
||||
end
|
||||
|
||||
def test_rendering_included_page_under_different_modes
|
||||
included = @web.add_page('Included', 'link to HomePage', Time.now, 'AnAuthor', test_renderer)
|
||||
main = @web.add_page('Main', '[[!include Included]]', Time.now, 'AnAuthor', test_renderer)
|
||||
|
||||
assert_equal '<p>link to <a class="existingWikiWord" href="../show/HomePage">Home Page</a></p>',
|
||||
test_renderer(main).display_content
|
||||
assert_equal '<p>link to <a class="existingWikiWord" href="../published/HomePage">Home Page</a></p>',
|
||||
test_renderer(main).display_published
|
||||
assert_equal '<p>link to <a class="existingWikiWord" href="HomePage.html">Home Page</a></p>',
|
||||
test_renderer(main).display_content_for_export
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def add_sample_pages
|
||||
|
|
Loading…
Reference in a new issue