2005-01-24 19:52:04 +01:00
|
|
|
require 'chunks/wiki'
|
|
|
|
|
|
|
|
# Includes the contents of another page for rendering.
|
|
|
|
# The include command looks like this: "[[!include PageName]]".
|
2005-03-27 20:13:43 +02:00
|
|
|
# It is a WikiReference since it refers to another page (PageName)
|
2005-01-24 19:52:04 +01:00
|
|
|
# and the wiki content using this command must be notified
|
|
|
|
# of changes to that page.
|
|
|
|
# If the included page could not be found, a warning is displayed.
|
2005-03-27 20:13:43 +02:00
|
|
|
|
|
|
|
class Include < WikiChunk::WikiReference
|
|
|
|
|
2005-05-12 02:56:57 +02:00
|
|
|
INCLUDE_PATTERN = /\[\[!include\s+(.*?)\]\]\s*/i
|
2005-02-04 20:00:28 +01:00
|
|
|
def self.pattern() INCLUDE_PATTERN end
|
2005-01-24 19:52:04 +01:00
|
|
|
|
|
|
|
|
2005-03-27 20:13:43 +02:00
|
|
|
def initialize(match_data, content)
|
|
|
|
super
|
2005-01-24 19:52:04 +01:00
|
|
|
@page_name = match_data[1].strip
|
2005-03-27 20:13:43 +02:00
|
|
|
@unmask_text = get_unmask_text_avoiding_recursion_loops
|
2005-01-24 19:52:04 +01:00
|
|
|
end
|
|
|
|
|
2005-03-27 20:13:43 +02:00
|
|
|
private
|
|
|
|
|
|
|
|
def get_unmask_text_avoiding_recursion_loops
|
|
|
|
if refpage then
|
2005-07-30 08:39:34 +02:00
|
|
|
refpage.clear_display_cache
|
2005-08-02 05:23:05 +02:00
|
|
|
if refpage.name == @content.page_name or refpage.wiki_includes.include?(@content.page_name)
|
2005-03-27 20:13:43 +02:00
|
|
|
# this will break the recursion
|
|
|
|
@content.delete_chunk(self)
|
|
|
|
return "<em>Recursive include detected; #{@page_name} --> #{@content.page_name} " +
|
|
|
|
"--> #{@page_name}</em>\n"
|
|
|
|
else
|
|
|
|
@content.merge_chunks(refpage.display_content)
|
|
|
|
return refpage.display_content.pre_rendered
|
|
|
|
end
|
|
|
|
else
|
|
|
|
return "<em>Could not include #{@page_name}</em>\n"
|
|
|
|
end
|
2005-01-24 19:52:04 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|