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

@ -34,11 +34,29 @@ class Revision
number > 0 ? page.revisions[number - 1] : nil
end
# Returns an array of all the WikiIncludes present in the content of this revision.
def wiki_includes
unless @wiki_includes_cache
chunks = display_content.find_chunks(Include)
@wiki_includes_cache = chunks.map { |c| ( c.escaped? ? nil : c.page_name ) }.compact.uniq
end
@wiki_includes_cache
end
# Returns an array of all the WikiReferences present in the content of this revision.
def wiki_references
unless @wiki_references_cache
chunks = display_content.find_chunks(WikiChunk::WikiReference)
@wiki_references_cache = chunks.map { |c| ( c.escaped? ? nil : c.page_name ) }.compact.uniq
end
@wiki_references_cache
end
# Returns an array of all the WikiWords present in the content of this revision.
def wiki_words
unless @wiki_words_cache
wiki_chunks = display_content.find_chunks(WikiChunk::WikiLink)
@wiki_words_cache = wiki_chunks.map { |c| ( c.escaped_text ? nil : c.page_name ) }.compact.uniq
@wiki_words_cache = wiki_chunks.map { |c| ( c.escaped? ? nil : c.page_name ) }.compact.uniq
end
@wiki_words_cache
end
@ -55,11 +73,12 @@ class Revision
wiki_words - existing_pages
end
# Explicit check for new type of display cache with find_chunks method.
# Explicit check for new type of display cache with chunks_by_type method.
# Ensures new version works with older snapshots.
def display_content
unless @display_cache && @display_cache.respond_to?(:find_chunks)
unless @display_cache && @display_cache.respond_to?(:chunks_by_type)
@display_cache = WikiContent.new(self)
@display_cache.render!
end
@display_cache
end
@ -69,7 +88,7 @@ class Revision
end
def clear_display_cache
@display_cache = @published_cache = @wiki_words_cache = nil
@wiki_references_cache = @wiki_includes = @display_cache = nil
end
def display_published
@ -78,12 +97,12 @@ class Revision
end
def display_content_for_export
WikiContent.new(self, {:mode => :export} )
WikiContent.new(self, {:mode => :export} ).render!
end
def force_rendering
begin
display_content
display_content.render!
rescue Exception => e
ApplicationController.logger.error "Failed rendering page #{@name}"
ApplicationController.logger.error e