Refactoring of chunks and rendering [Denis Mertz]

This commit is contained in:
Alexey Verkhovsky 2005-03-27 18:13:43 +00:00
parent a87ef98aef
commit 78bad46419
19 changed files with 365 additions and 180 deletions

View file

@ -2,29 +2,40 @@ require 'chunks/wiki'
# Includes the contents of another page for rendering.
# The include command looks like this: "[[!include PageName]]".
# It is a WikiLink since it refers to another page (PageName)
# It is a WikiReference since it refers to another page (PageName)
# 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.
class Include < WikiChunk::WikiLink
INCLUDE_PATTERN = /^\[\[!include(.*)\]\]\s*$/i
class Include < WikiChunk::WikiReference
INCLUDE_PATTERN = /\[\[!include(.*)\]\]\s*/i
def self.pattern() INCLUDE_PATTERN end
attr_reader :page_name
def initialize(match_data)
super(match_data)
def initialize(match_data, content)
super
@page_name = match_data[1].strip
@unmask_text = get_unmask_text_avoiding_recursion_loops
end
# This replaces the [[!include PageName]] text with
# the contents of PageName if it exists. Otherwise
# a warning is displayed.
def mask(content)
page = content.web.pages[page_name]
(page ? page.content : "<em>Could not include #{page_name}</em>")
private
def get_unmask_text_avoiding_recursion_loops
if refpage then
if refpage.wiki_includes.include?(@content.page_name)
# this will break the recursion
@content.delete_chunk(self)
refpage.clear_display_cache
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
end
# Keep this chunk regardless of what happens.
def unmask(content) self end
end