Included pages
Redirects and categories of included pages should not be inherited. (Suggestion of Andrew Stacey)
This commit is contained in:
parent
bf69cceb25
commit
bb17fbbe02
3 changed files with 42 additions and 2 deletions
|
@ -36,7 +36,8 @@ class Include < WikiChunk::WikiReference
|
|||
else
|
||||
raise "Unsupported rendering mode #{@mode.inspect}"
|
||||
end
|
||||
@content.merge_chunks(included_content)
|
||||
# redirects and categories of included pages should not be inherited
|
||||
@content.merge_chunks(included_content.delete_chunks!([Redirect, Category]))
|
||||
clear_include_list
|
||||
return included_content.pre_rendered
|
||||
else
|
||||
|
|
|
@ -185,6 +185,16 @@ class WikiContent < ActiveSupport::SafeBuffer
|
|||
end
|
||||
end
|
||||
|
||||
def delete_chunks!(types)
|
||||
types.each do |t|
|
||||
@chunks_by_type[t].each do |c|
|
||||
@pre_rendered.sub!(c.mask, '') if @pre_rendered
|
||||
@chunks.delete(c)
|
||||
end
|
||||
end
|
||||
self
|
||||
end
|
||||
|
||||
def pre_render!
|
||||
unless @pre_rendered
|
||||
@chunks_by_type[Include].each{|chunk| chunk.unmask }
|
||||
|
|
|
@ -743,7 +743,36 @@ END_THM
|
|||
assert_equal WikiReference::INCLUDED_PAGE, references[0].link_type
|
||||
end
|
||||
|
||||
def test_references_creation_categories
|
||||
def test_references_creation_redirects
|
||||
new_page = @web.add_page('NewPage', '[[!redirects OtherPage]]',
|
||||
Time.local(2004, 4, 4, 16, 50), 'AlexeyVerkhovsky', x_test_renderer)
|
||||
|
||||
references = new_page.wiki_references(true)
|
||||
assert_equal 1, references.size
|
||||
assert_equal 'OtherPage', references[0].referenced_name
|
||||
assert_equal WikiReference::REDIRECTED_PAGE, references[0].link_type
|
||||
end
|
||||
|
||||
def test_references_creation_redirects_in_included_page
|
||||
new_page = @web.add_page('NewPage', "[[!redirects OtherPage]]\ncategory: plants",
|
||||
Time.local(2004, 4, 4, 16, 50), 'AlexeyVerkhovsky', x_test_renderer)
|
||||
second_page = @web.add_page('SecondPage', '[[!include NewPage]]',
|
||||
Time.local(2004, 4, 4, 16, 50), 'AlexeyVerkhovsky', x_test_renderer)
|
||||
|
||||
references = new_page.wiki_references(true)
|
||||
assert_equal 2, references.size
|
||||
assert_equal 'OtherPage', references[0].referenced_name
|
||||
assert_equal WikiReference::REDIRECTED_PAGE, references[0].link_type
|
||||
assert_equal 'plants', references[1].referenced_name
|
||||
assert_equal WikiReference::CATEGORY, references[1].link_type
|
||||
|
||||
references = second_page.wiki_references(true)
|
||||
assert_equal 1, references.size
|
||||
assert_equal 'NewPage', references[0].referenced_name
|
||||
assert_equal WikiReference::INCLUDED_PAGE, references[0].link_type
|
||||
end
|
||||
|
||||
def test_references_creation_categories
|
||||
new_page = @web.add_page('NewPage', "Foo\ncategory: NewPageCategory",
|
||||
Time.local(2004, 4, 4, 16, 50), 'AlexeyVerkhovsky', x_test_renderer)
|
||||
|
||||
|
|
Loading…
Reference in a new issue