This commit is contained in:
Alexey Verkhovsky 2006-09-07 04:07:51 +00:00
parent 839dc364dd
commit 4b29a843e5
2 changed files with 22 additions and 3 deletions

View file

@ -15,12 +15,13 @@ class Include < WikiChunk::WikiReference
def initialize(match_data, content) def initialize(match_data, content)
super super
@page_name = match_data[1].strip @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 end
private private
def get_unmask_text_avoiding_recursion_loops def get_unmask_text_avoiding_recursion_loops(rendering_mode)
if refpage if refpage
# TODO This way of instantiating a renderer is ugly. # TODO This way of instantiating a renderer is ugly.
renderer = PageRenderer.new(refpage.current_revision) renderer = PageRenderer.new(refpage.current_revision)
@ -30,7 +31,13 @@ class Include < WikiChunk::WikiReference
return "<em>Recursive include detected; #{@page_name} --> #{@content.page_name} " + return "<em>Recursive include detected; #{@page_name} --> #{@content.page_name} " +
"--> #{@page_name}</em>\n" "--> #{@page_name}</em>\n"
else 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) @content.merge_chunks(included_content)
return included_content.pre_rendered return included_content.pre_rendered
end end

View file

@ -355,6 +355,18 @@ class PageRendererTest < Test::Unit::TestCase
assert_equal 'NewPageCategory', references[0].referenced_name assert_equal 'NewPageCategory', references[0].referenced_name
assert_equal WikiReference::CATEGORY, references[0].link_type assert_equal WikiReference::CATEGORY, references[0].link_type
end 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 private