Page will try to render itself in revise method, and behave appropriately if markup engine fails [inspired by Denis]
This commit is contained in:
parent
2e9e82bd0a
commit
85bc93984d
|
@ -94,9 +94,15 @@ class FileController < ApplicationController
|
|||
page_content = entry.get_input_stream.read
|
||||
logger.info "Processing page '#{page_name}'"
|
||||
begin
|
||||
if @wiki.read_page(@web.address, page_name)
|
||||
logger.info "Page '#{page_name}' already exists. Adding a new revision to it."
|
||||
wiki.revise_page(@web.address, page_name, page_content, Time.now, @author)
|
||||
existing_page = @wiki.read_page(@web.address, page_name)
|
||||
if existing_page
|
||||
if existing_page.content == page_content
|
||||
logger.info "Page '#{page_name}' with the same content already exists. Skipping."
|
||||
next
|
||||
else
|
||||
logger.info "Page '#{page_name}' already exists. Adding a new revision to it."
|
||||
wiki.revise_page(@web.address, page_name, page_content, Time.now, @author)
|
||||
end
|
||||
else
|
||||
wiki.write_page(@web.address, page_name, page_content, Time.now, @author)
|
||||
end
|
||||
|
|
|
@ -34,7 +34,13 @@ class Page
|
|||
@revisions << Revision.new(self, @revisions.length, content, created_at, author)
|
||||
end
|
||||
|
||||
web.refresh_pages_with_references(name) if @revisions.length == 1
|
||||
self.revisions.last.force_rendering
|
||||
# at this point the page may not be inserted in the web yet, and therefore
|
||||
# references to the page itself are rendered as "unresolved". Clearing the cache allows
|
||||
# the page to re-render itself once again, hopefully _after_ it is inserted in the web
|
||||
self.revisions.last.clear_display_cache
|
||||
|
||||
web.refresh_pages_with_references(@name) if @revisions.length == 1
|
||||
end
|
||||
|
||||
def rollback(revision_number, created_at, author_ip = nil)
|
||||
|
@ -79,14 +85,16 @@ class Page
|
|||
web.make_link(author, nil, options)
|
||||
end
|
||||
|
||||
private
|
||||
def continous_revision?(created_at, author)
|
||||
@revisions.last.author == author && @revisions.last.created_at + 30.minutes > created_at
|
||||
end
|
||||
|
||||
# Forward method calls to the current revision, so the page responds to all revision calls
|
||||
def method_missing(method_symbol)
|
||||
revisions.last.send(method_symbol)
|
||||
end
|
||||
private
|
||||
|
||||
def continous_revision?(created_at, author)
|
||||
@revisions.last.author == author && @revisions.last.created_at + 30.minutes > created_at
|
||||
end
|
||||
|
||||
# Forward method calls to the current revision, so the page responds to all revision calls
|
||||
def method_missing(method_symbol)
|
||||
revisions.last.send(method_symbol)
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -80,4 +80,20 @@ class Revision
|
|||
WikiContent.new(self, {:mode => :export} )
|
||||
end
|
||||
|
||||
def force_rendering
|
||||
begin
|
||||
display_content
|
||||
rescue Exception => e
|
||||
ApplicationController.logger.error "Failed rendering page #{@name}"
|
||||
ApplicationController.logger.error e
|
||||
message = e.message.gsub(/\n/, '<br/>')
|
||||
# substitute content with an error message
|
||||
content = <<-EOL
|
||||
<p>Markup engine has failed to render this page, raising the following error:</p>
|
||||
<p>#{message}</p>
|
||||
EOL
|
||||
raise e
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue