Extacted rendering logic from the model
This commit is contained in:
parent
acfae2818c
commit
427f989d69
19 changed files with 550 additions and 525 deletions
|
@ -17,7 +17,6 @@ class FileController < ApplicationController
|
||||||
# form supplied
|
# form supplied
|
||||||
file_yard.upload_file(@file_name, @params['file'])
|
file_yard.upload_file(@file_name, @params['file'])
|
||||||
flash[:info] = "File '#{@file_name}' successfully uploaded"
|
flash[:info] = "File '#{@file_name}' successfully uploaded"
|
||||||
@web.refresh_pages_with_references(@file_name)
|
|
||||||
return_to_last_remembered
|
return_to_last_remembered
|
||||||
elsif file_yard.has_file?(@file_name)
|
elsif file_yard.has_file?(@file_name)
|
||||||
send_file(file_yard.file_path(@file_name))
|
send_file(file_yard.file_path(@file_name))
|
||||||
|
@ -36,7 +35,6 @@ class FileController < ApplicationController
|
||||||
if @params['file']
|
if @params['file']
|
||||||
# form supplied
|
# form supplied
|
||||||
file_yard.upload_file(@file_name, @params['file'])
|
file_yard.upload_file(@file_name, @params['file'])
|
||||||
@web.refresh_pages_with_references(@file_name)
|
|
||||||
flash[:info] = "Image '#{@file_name}' successfully uploaded"
|
flash[:info] = "Image '#{@file_name}' successfully uploaded"
|
||||||
return_to_last_remembered
|
return_to_last_remembered
|
||||||
elsif file_yard.has_file?(@file_name)
|
elsif file_yard.has_file?(@file_name)
|
||||||
|
|
|
@ -48,6 +48,7 @@ class WikiController < ApplicationController
|
||||||
def export_html
|
def export_html
|
||||||
export_pages_as_zip('html') do |page|
|
export_pages_as_zip('html') do |page|
|
||||||
@page = page
|
@page = page
|
||||||
|
@renderer = PageRenderer.new(page.revisions.last)
|
||||||
@link_mode = :export
|
@link_mode = :export
|
||||||
render_to_string('wiki/print', use_layout = (@params['layout'] != 'no'))
|
render_to_string('wiki/print', use_layout = (@params['layout'] != 'no'))
|
||||||
end
|
end
|
||||||
|
@ -152,12 +153,14 @@ class WikiController < ApplicationController
|
||||||
|
|
||||||
def print
|
def print
|
||||||
@link_mode ||= :show
|
@link_mode ||= :show
|
||||||
|
@renderer = PageRenderer.new(@page.revisions.last)
|
||||||
# to template
|
# to template
|
||||||
end
|
end
|
||||||
|
|
||||||
def published
|
def published
|
||||||
if @web.published?
|
if @web.published?
|
||||||
@page = wiki.read_page(@web_name, @page_name || 'HomePage')
|
page = wiki.read_page(@web_name, @page_name || 'HomePage')
|
||||||
|
@renderer = PageRenderer.new(page.revisions.last)
|
||||||
else
|
else
|
||||||
redirect_home
|
redirect_home
|
||||||
end
|
end
|
||||||
|
@ -165,6 +168,7 @@ class WikiController < ApplicationController
|
||||||
|
|
||||||
def revision
|
def revision
|
||||||
get_page_and_revision
|
get_page_and_revision
|
||||||
|
@renderer = PageRenderer.new(@revision)
|
||||||
end
|
end
|
||||||
|
|
||||||
def rollback
|
def rollback
|
||||||
|
@ -200,6 +204,7 @@ class WikiController < ApplicationController
|
||||||
def show
|
def show
|
||||||
if @page
|
if @page
|
||||||
begin
|
begin
|
||||||
|
@renderer = PageRenderer.new(@page.revisions.last)
|
||||||
render_action 'page'
|
render_action 'page'
|
||||||
# TODO this rescue should differentiate between errors due to rendering and errors in
|
# TODO this rescue should differentiate between errors due to rendering and errors in
|
||||||
# the application itself (for application errors, it's better not to rescue the error at all)
|
# the application itself (for application errors, it's better not to rescue the error at all)
|
||||||
|
@ -280,14 +285,20 @@ class WikiController < ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
def parse_category
|
def parse_category
|
||||||
@categories = @web.categories
|
|
||||||
@category = @params['category']
|
@category = @params['category']
|
||||||
if @categories.include?(@category)
|
@categories = []
|
||||||
@pages_in_category = @web.select { |page| page.in_category?(@category) }
|
@pages_in_category = @web.select do |page|
|
||||||
@set_name = "category '#{@category}'"
|
page_categories = PageRenderer.new(page.revisions.last).display_content.find_chunks(Category)
|
||||||
else
|
page_categories = page_categories.map { |cat| cat.list }.flatten
|
||||||
|
page_categories.each {|c| @categories << c unless @categories.include? c }
|
||||||
|
page_categories.include?(@category)
|
||||||
|
end
|
||||||
|
@categories.sort!
|
||||||
|
if (@pages_in_category.empty?)
|
||||||
@pages_in_category = PageSet.new(@web).by_name
|
@pages_in_category = PageSet.new(@web).by_name
|
||||||
@set_name = 'the web'
|
@set_name = 'the web'
|
||||||
|
else
|
||||||
|
@set_name = "category '#{@category}'"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -78,4 +78,8 @@ module ApplicationHelper
|
||||||
date.sec).strftime("%B %e, %Y %H:%M:%S")
|
date.sec).strftime("%B %e, %Y %H:%M:%S")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def rendered_content(page)
|
||||||
|
PageRenderer.new(page.revisions.last).display_content
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -24,10 +24,7 @@ class Page < ActiveRecord::Base
|
||||||
else
|
else
|
||||||
Revision.create(:page => self, :content => content, :author => author, :revised_at => time)
|
Revision.create(:page => self, :content => content, :author => author, :revised_at => time)
|
||||||
end
|
end
|
||||||
|
|
||||||
save
|
save
|
||||||
web.refresh_pages_with_references(name) if revisions_size == 0
|
|
||||||
|
|
||||||
self
|
self
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -58,14 +55,6 @@ class Page < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def in_category?(cat)
|
|
||||||
cat.nil? || cat.empty? || categories.include?(cat)
|
|
||||||
end
|
|
||||||
|
|
||||||
def categories
|
|
||||||
display_content.find_chunks(Category).map { |cat| cat.list }.flatten
|
|
||||||
end
|
|
||||||
|
|
||||||
def authors
|
def authors
|
||||||
revisions.collect { |rev| rev.author }
|
revisions.collect { |rev| rev.author }
|
||||||
end
|
end
|
||||||
|
|
|
@ -31,15 +31,15 @@ class PageSet < Array
|
||||||
end
|
end
|
||||||
|
|
||||||
def pages_that_reference(page_name)
|
def pages_that_reference(page_name)
|
||||||
self.select { |page| page.wiki_references.include?(page_name) }
|
self.select { |page| PageRenderer.new(page.revisions.last).wiki_references.include?(page_name) }
|
||||||
end
|
end
|
||||||
|
|
||||||
def pages_that_link_to(page_name)
|
def pages_that_link_to(page_name)
|
||||||
self.select { |page| page.wiki_words.include?(page_name) }
|
self.select { |page| PageRenderer.new(page.revisions.last).wiki_words.include?(page_name) }
|
||||||
end
|
end
|
||||||
|
|
||||||
def pages_that_include(page_name)
|
def pages_that_include(page_name)
|
||||||
self.select { |page| page.wiki_includes.include?(page_name) }
|
self.select { |page| PageRenderer.new(page.revisions.last).wiki_includes.include?(page_name) }
|
||||||
end
|
end
|
||||||
|
|
||||||
def pages_authored_by(author)
|
def pages_authored_by(author)
|
||||||
|
@ -78,7 +78,7 @@ class PageSet < Array
|
||||||
end
|
end
|
||||||
|
|
||||||
def wiki_words
|
def wiki_words
|
||||||
self.inject([]) { |wiki_words, page| wiki_words << page.wiki_words }.flatten.uniq
|
self.inject([]) { |wiki_words, page| wiki_words << PageRenderer.new(page.revisions.last).wiki_words }.flatten.uniq
|
||||||
end
|
end
|
||||||
|
|
||||||
def authors
|
def authors
|
||||||
|
|
|
@ -3,103 +3,10 @@ class Revision < ActiveRecord::Base
|
||||||
belongs_to :page
|
belongs_to :page
|
||||||
composed_of :author, :mapping => [ %w(author name), %w(ip ip) ]
|
composed_of :author, :mapping => [ %w(author name), %w(ip ip) ]
|
||||||
|
|
||||||
# Returns an array of all the WikiIncludes present in the content of this revision.
|
after_create :force_rendering
|
||||||
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? ? nil : c.page_name ) }.compact.uniq
|
|
||||||
end
|
|
||||||
@wiki_words_cache
|
|
||||||
end
|
|
||||||
|
|
||||||
# Returns an array of all the WikiWords present in the content of this revision.
|
|
||||||
# that already exists as a page in the web.
|
|
||||||
def existing_pages
|
|
||||||
wiki_words.select { |wiki_word| page.web.page(wiki_word) }
|
|
||||||
end
|
|
||||||
|
|
||||||
# Returns an array of all the WikiWords present in the content of this revision
|
|
||||||
# that *doesn't* already exists as a page in the web.
|
|
||||||
def unexisting_pages
|
|
||||||
wiki_words - existing_pages
|
|
||||||
end
|
|
||||||
|
|
||||||
# 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?(:chunks_by_type)
|
|
||||||
@display_cache = WikiContent.new(self)
|
|
||||||
@display_cache.render!
|
|
||||||
end
|
|
||||||
@display_cache
|
|
||||||
end
|
|
||||||
|
|
||||||
# TODO this probably doesn't belong in revision (because it has to call back the page)
|
|
||||||
def display_diff
|
|
||||||
previous_revision = page.previous_revision(self)
|
|
||||||
if previous_revision
|
|
||||||
HTMLDiff.diff(previous_revision.display_content, display_content)
|
|
||||||
else
|
|
||||||
display_content
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def clear_display_cache
|
|
||||||
@wiki_words_cache = @published_cache = @display_cache = @wiki_includes_cache =
|
|
||||||
@wiki_references_cache = nil
|
|
||||||
end
|
|
||||||
|
|
||||||
def display_published
|
|
||||||
unless @published_cache && @published_cache.respond_to?(:chunks_by_type)
|
|
||||||
@published_cache = WikiContent.new(self, {:mode => :publish})
|
|
||||||
@published_cache.render!
|
|
||||||
end
|
|
||||||
@published_cache
|
|
||||||
end
|
|
||||||
|
|
||||||
def display_content_for_export
|
|
||||||
WikiContent.new(self, {:mode => :export} ).render!
|
|
||||||
end
|
|
||||||
|
|
||||||
def force_rendering
|
def force_rendering
|
||||||
begin
|
PageRenderer.new(self).force_rendering
|
||||||
display_content.render!
|
|
||||||
rescue => e
|
|
||||||
logger.error "Failed rendering page #{@name}"
|
|
||||||
logger.error e
|
|
||||||
message = e.message
|
|
||||||
# substitute content with an error message
|
|
||||||
self.content = <<-EOL
|
|
||||||
<p>Markup engine has failed to render this page, raising the following error:</p>
|
|
||||||
<p>#{message}</p>
|
|
||||||
<pre>#{self.content}</pre>
|
|
||||||
EOL
|
|
||||||
clear_display_cache
|
|
||||||
raise e
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
protected
|
|
||||||
|
|
||||||
after_create :force_rendering
|
|
||||||
after_save :clear_display_cache
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -66,17 +66,6 @@ class Web < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Clears the display cache for all the pages with references to
|
|
||||||
def refresh_pages_with_references(page_name)
|
|
||||||
#select.pages_that_reference(page_name).each { |page|
|
|
||||||
# page.revisions.each { |revision| revision.clear_display_cache }
|
|
||||||
#}
|
|
||||||
end
|
|
||||||
|
|
||||||
def refresh_revisions
|
|
||||||
select.each { |page| page.revisions.each { |revision| revision.clear_display_cache } }
|
|
||||||
end
|
|
||||||
|
|
||||||
def remove_pages(pages_to_be_removed)
|
def remove_pages(pages_to_be_removed)
|
||||||
pages_to_be_removed.each { |p| p.destroy }
|
pages_to_be_removed.each { |p| p.destroy }
|
||||||
end
|
end
|
||||||
|
|
|
@ -32,7 +32,6 @@ class Wiki
|
||||||
raise Instiki::ValidationError.new("Web with address '#{old_address}' does not exist")
|
raise Instiki::ValidationError.new("Web with address '#{old_address}' does not exist")
|
||||||
end
|
end
|
||||||
|
|
||||||
web.refresh_revisions if web.settings_changed?(markup, safe_mode, brackets_only)
|
|
||||||
web.update_attributes(:address => new_address, :name => name, :markup => markup, :color => color,
|
web.update_attributes(:address => new_address, :name => name, :markup => markup, :color => color,
|
||||||
:additional_style => additional_style, :safe_mode => safe_mode, :password => password, :published => published,
|
:additional_style => additional_style, :safe_mode => safe_mode, :password => password, :published => published,
|
||||||
:brackets_only => brackets_only, :count_pages => count_pages, :allow_uploads => allow_uploads, :max_upload_size => max_upload_size)
|
:brackets_only => brackets_only, :count_pages => count_pages, :allow_uploads => allow_uploads, :max_upload_size => max_upload_size)
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
%>
|
%>
|
||||||
|
|
||||||
<div id="revision">
|
<div id="revision">
|
||||||
<%= @page.display_content %>
|
<%= @renderer.display_content %>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
@ -17,7 +17,7 @@
|
||||||
</small>
|
</small>
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<%= @page.display_diff %>
|
<%= @renderer.display_diff %>
|
||||||
</div>
|
</div>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
@inline_style = true
|
@inline_style = true
|
||||||
%>
|
%>
|
||||||
|
|
||||||
<%= @page.display_content_for_export %>
|
<%= @renderer.display_content_for_export %>
|
||||||
|
|
||||||
<div class="byline">
|
<div class="byline">
|
||||||
<%= @page.revisions? ? "Revised" : "Created" %> on <%= format_date(@page.revised_at) %>
|
<%= @page.revisions? ? "Revised" : "Created" %> on <%= format_date(@page.revised_at) %>
|
||||||
|
|
|
@ -6,4 +6,4 @@
|
||||||
@show_footer = true
|
@show_footer = true
|
||||||
%>
|
%>
|
||||||
|
|
||||||
<%= @page.display_published %>
|
<%= @renderer.display_published %>
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
<% @title = "#{@page.plain_name} (Rev ##{@revision_number})" %>
|
<% @title = "#{@page.plain_name} (Rev ##{@revision_number})" %>
|
||||||
|
|
||||||
<div id="revision">
|
<div id="revision">
|
||||||
<%= @revision.display_content %>
|
<%= @renderer.display_content %>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div id="changes" style="display: none">
|
<div id="changes" style="display: none">
|
||||||
|
@ -12,7 +12,7 @@
|
||||||
</small>
|
</small>
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<%= @revision.display_diff %>
|
<%= @renderer.display_diff %>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -10,7 +10,7 @@
|
||||||
<item>
|
<item>
|
||||||
<title><%= h page.plain_name %></title>
|
<title><%= h page.plain_name %></title>
|
||||||
<% unless @hide_description %>
|
<% unless @hide_description %>
|
||||||
<description><%= h page.display_content %></description>
|
<description><%= h rendered_content(page) %></description>
|
||||||
<% end %>
|
<% end %>
|
||||||
<pubDate><%= page.revised_at.getgm.strftime "%a, %d %b %Y %H:%M:%S Z" %></pubDate>
|
<pubDate><%= page.revised_at.getgm.strftime "%a, %d %b %Y %H:%M:%S Z" %></pubDate>
|
||||||
<guid><%= url_for :only_path => false, :web => @web_name, :action => @link_action, :id => page.name %></guid>
|
<guid><%= url_for :only_path => false, :web => @web_name, :action => @link_action, :id => page.name %></guid>
|
||||||
|
|
|
@ -1,4 +1,14 @@
|
||||||
Dependencies.mechanism = :require
|
# In the development environment your application's code is reloaded on
|
||||||
|
# every request. This slows down response time but is perfect for development
|
||||||
|
# since you don't have to restart the webserver when you make code changes.
|
||||||
|
|
||||||
|
# Log error messages when you accidentally call methods on nil.
|
||||||
|
require 'active_support/whiny_nil'
|
||||||
|
|
||||||
|
# Reload code; show full error reports; disable caching.
|
||||||
|
Dependencies.mechanism = :load
|
||||||
ActionController::Base.consider_all_requests_local = true
|
ActionController::Base.consider_all_requests_local = true
|
||||||
ActionController::Base.perform_caching = false
|
ActionController::Base.perform_caching = false
|
||||||
|
|
||||||
|
# The breakpoint server port that script/breakpointer connects to.
|
||||||
BREAKPOINT_SERVER_PORT = 42531
|
BREAKPOINT_SERVER_PORT = 42531
|
||||||
|
|
106
lib/page_renderer.rb
Normal file
106
lib/page_renderer.rb
Normal file
|
@ -0,0 +1,106 @@
|
||||||
|
# Temporary class containing all rendering stuff from a Revision
|
||||||
|
# I want to shift all rendering loguc to the controller eventually
|
||||||
|
|
||||||
|
class PageRenderer
|
||||||
|
|
||||||
|
def initialize(revision)
|
||||||
|
@revision = revision
|
||||||
|
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? ? nil : c.page_name ) }.compact.uniq
|
||||||
|
end
|
||||||
|
@wiki_words_cache
|
||||||
|
end
|
||||||
|
|
||||||
|
# Returns an array of all the WikiWords present in the content of this revision.
|
||||||
|
# that already exists as a page in the web.
|
||||||
|
def existing_pages
|
||||||
|
wiki_words.select { |wiki_word| @revision.page.web.page(wiki_word) }
|
||||||
|
end
|
||||||
|
|
||||||
|
# Returns an array of all the WikiWords present in the content of this revision
|
||||||
|
# that *doesn't* already exists as a page in the web.
|
||||||
|
def unexisting_pages
|
||||||
|
wiki_words - existing_pages
|
||||||
|
end
|
||||||
|
|
||||||
|
# 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?(:chunks_by_type)
|
||||||
|
@display_cache = WikiContent.new(@revision)
|
||||||
|
@display_cache.render!
|
||||||
|
end
|
||||||
|
@display_cache
|
||||||
|
end
|
||||||
|
|
||||||
|
# TODO this probably doesn't belong in revision (because it has to call back the page)
|
||||||
|
def display_diff
|
||||||
|
previous_revision = @revision.page.previous_revision(@revision)
|
||||||
|
if previous_revision
|
||||||
|
HTMLDiff.diff(PageRenderer.new(previous_revision).display_content, display_content)
|
||||||
|
else
|
||||||
|
display_content
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def clear_display_cache
|
||||||
|
@wiki_words_cache = @published_cache = @display_cache = @wiki_includes_cache =
|
||||||
|
@wiki_references_cache = nil
|
||||||
|
end
|
||||||
|
|
||||||
|
def display_published
|
||||||
|
unless @published_cache && @published_cache.respond_to?(:chunks_by_type)
|
||||||
|
@published_cache = WikiContent.new(@revision, {:mode => :publish})
|
||||||
|
@published_cache.render!
|
||||||
|
end
|
||||||
|
@published_cache
|
||||||
|
end
|
||||||
|
|
||||||
|
def display_content_for_export
|
||||||
|
WikiContent.new(@revision, {:mode => :export} ).render!
|
||||||
|
end
|
||||||
|
|
||||||
|
def force_rendering
|
||||||
|
begin
|
||||||
|
display_content.render!
|
||||||
|
rescue => e
|
||||||
|
logger.error "Failed rendering page #{@name}"
|
||||||
|
logger.error e
|
||||||
|
message = e.message
|
||||||
|
# substitute content with an error message
|
||||||
|
@revision.content = <<-EOL
|
||||||
|
<p>Markup engine has failed to render this page, raising the following error:</p>
|
||||||
|
<p>#{message}</p>
|
||||||
|
<pre>#{self.content}</pre>
|
||||||
|
EOL
|
||||||
|
clear_display_cache
|
||||||
|
raise e
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
protected
|
||||||
|
|
||||||
|
end
|
|
@ -96,7 +96,7 @@ class FileControllerTest < Test::Unit::TestCase
|
||||||
@wiki.revise_page('wiki1', 'HomePage', '[[instiki-e2e.txt:file]]', Time.now, 'AnonymousBrave')
|
@wiki.revise_page('wiki1', 'HomePage', '[[instiki-e2e.txt:file]]', Time.now, 'AnonymousBrave')
|
||||||
assert_equal "<p><span class=\"newWikiWord\">instiki-e2e.txt" +
|
assert_equal "<p><span class=\"newWikiWord\">instiki-e2e.txt" +
|
||||||
"<a href=\"../file/instiki-e2e.txt\">?</a></span></p>",
|
"<a href=\"../file/instiki-e2e.txt\">?</a></span></p>",
|
||||||
@home.display_content
|
PageRenderer.new(@home.revisions.last).display_content
|
||||||
|
|
||||||
# rails-e2e.gif is unknown to the system, so pic action goes to the file [upload] form
|
# rails-e2e.gif is unknown to the system, so pic action goes to the file [upload] form
|
||||||
r = process 'file', 'web' => 'wiki1', 'id' => 'instiki-e2e.txt'
|
r = process 'file', 'web' => 'wiki1', 'id' => 'instiki-e2e.txt'
|
||||||
|
@ -114,7 +114,7 @@ class FileControllerTest < Test::Unit::TestCase
|
||||||
@home = Page.find(@home.id)
|
@home = Page.find(@home.id)
|
||||||
assert_equal "<p><a class=\"existingWikiWord\" href=\"../file/instiki-e2e.txt\">" +
|
assert_equal "<p><a class=\"existingWikiWord\" href=\"../file/instiki-e2e.txt\">" +
|
||||||
"instiki-e2e.txt</a></p>",
|
"instiki-e2e.txt</a></p>",
|
||||||
@home.display_content
|
PageRenderer.new(@home.revisions.last).display_content
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_uploads_blocking
|
def test_uploads_blocking
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
|
require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
|
||||||
|
|
||||||
class RevisionTest < Test::Unit::TestCase
|
class PageRendererTest < Test::Unit::TestCase
|
||||||
fixtures :webs, :pages, :revisions, :system
|
fixtures :webs, :pages, :revisions, :system
|
||||||
|
|
||||||
def setup
|
def setup
|
||||||
|
@ -10,19 +10,79 @@ class RevisionTest < Test::Unit::TestCase
|
||||||
@revision = revisions(:home_page_second_revision)
|
@revision = revisions(:home_page_second_revision)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_wiki_word_linking
|
||||||
|
@web.add_page('SecondPage', 'Yo, yo. Have you EverBeenHated',
|
||||||
|
Time.now, 'DavidHeinemeierHansson')
|
||||||
|
|
||||||
|
assert_equal('<p>Yo, yo. Have you <span class="newWikiWord">Ever Been Hated' +
|
||||||
|
'<a href="../show/EverBeenHated">?</a></span></p>',
|
||||||
|
rendered_content(@web.page("SecondPage")))
|
||||||
|
|
||||||
|
@web.add_page('EverBeenHated', 'Yo, yo. Have you EverBeenHated', Time.now,
|
||||||
|
'DavidHeinemeierHansson')
|
||||||
|
assert_equal('<p>Yo, yo. Have you <a class="existingWikiWord" ' +
|
||||||
|
'href="../show/EverBeenHated">Ever Been Hated</a></p>',
|
||||||
|
rendered_content(@web.page("SecondPage")))
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_make_link
|
||||||
|
add_sample_pages
|
||||||
|
|
||||||
|
existing_page_wiki_url =
|
||||||
|
'<a class="existingWikiWord" href="../show/EverBeenInLove">Ever Been In Love</a>'
|
||||||
|
existing_page_published_url =
|
||||||
|
'<a class="existingWikiWord" href="../published/EverBeenInLove">Ever Been In Love</a>'
|
||||||
|
existing_page_static_url =
|
||||||
|
'<a class="existingWikiWord" href="EverBeenInLove.html">Ever Been In Love</a>'
|
||||||
|
new_page_wiki_url =
|
||||||
|
'<span class="newWikiWord">Unknown Word<a href="../show/UnknownWord">?</a></span>'
|
||||||
|
new_page_published_url = new_page_static_url = '<span class="newWikiWord">Unknown Word</span>'
|
||||||
|
|
||||||
|
# no options
|
||||||
|
assert_equal existing_page_wiki_url, @web.make_link('EverBeenInLove')
|
||||||
|
|
||||||
|
# :mode => :export
|
||||||
|
assert_equal existing_page_static_url, @web.make_link('EverBeenInLove', nil, :mode => :export)
|
||||||
|
|
||||||
|
# :mode => :publish
|
||||||
|
assert_equal existing_page_published_url,
|
||||||
|
@web.make_link('EverBeenInLove', nil, :mode => :publish)
|
||||||
|
|
||||||
|
# new page, no options
|
||||||
|
assert_equal new_page_wiki_url, @web.make_link('UnknownWord')
|
||||||
|
|
||||||
|
# new page, :mode => :export
|
||||||
|
assert_equal new_page_static_url, @web.make_link('UnknownWord', nil, :mode => :export)
|
||||||
|
|
||||||
|
# new page, :mode => :publish
|
||||||
|
assert_equal new_page_published_url, @web.make_link('UnknownWord', nil, :mode => :publish)
|
||||||
|
|
||||||
|
# Escaping special characters in the name
|
||||||
|
assert_equal(
|
||||||
|
'<span class="newWikiWord">Smith & Wesson<a href="../show/Smith+%26+Wesson">?</a></span>',
|
||||||
|
@web.make_link('Smith & Wesson'))
|
||||||
|
|
||||||
|
# optionally using text as the link text
|
||||||
|
assert_equal(
|
||||||
|
existing_page_published_url.sub(/>Ever Been In Love</, ">Haven't you ever been in love?<"),
|
||||||
|
@web.make_link('EverBeenInLove', "Haven't you ever been in love?", :mode => :publish))
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
def test_wiki_words
|
def test_wiki_words
|
||||||
assert_equal %w( HisWay MyWay SmartEngine SmartEngineGUI ThatWay ), @revision.wiki_words.sort
|
assert_equal %w( HisWay MyWay SmartEngine SmartEngineGUI ThatWay ),
|
||||||
|
PageRenderer.new(@revision).wiki_words.sort
|
||||||
|
|
||||||
@wiki.write_page('wiki1', 'NoWikiWord', 'hey you!', Time.now, 'Me')
|
@wiki.write_page('wiki1', 'NoWikiWord', 'hey you!', Time.now, 'Me')
|
||||||
assert_equal [], @wiki.read_page('wiki1', 'NoWikiWord').wiki_words
|
assert_equal [], PageRenderer.new(@wiki.read_page('wiki1', 'NoWikiWord').revisions.last).wiki_words
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_existing_pages
|
def test_existing_pages
|
||||||
assert_equal %w( MyWay SmartEngine ThatWay ), @revision.existing_pages.sort
|
assert_equal %w( MyWay SmartEngine ThatWay ), PageRenderer.new(@revision).existing_pages.sort
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_unexisting_pages
|
def test_unexisting_pages
|
||||||
assert_equal %w( HisWay SmartEngineGUI ), @revision.unexisting_pages.sort
|
assert_equal %w( HisWay SmartEngineGUI ), PageRenderer.new(@revision).unexisting_pages.sort
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_content_with_wiki_links
|
def test_content_with_wiki_links
|
||||||
|
@ -34,7 +94,7 @@ class RevisionTest < Test::Unit::TestCase
|
||||||
'<a class="existingWikiWord" href="../show/SmartEngine">Smart Engine</a> in that ' +
|
'<a class="existingWikiWord" href="../show/SmartEngine">Smart Engine</a> in that ' +
|
||||||
'<span class="newWikiWord">Smart Engine GUI' +
|
'<span class="newWikiWord">Smart Engine GUI' +
|
||||||
'<a href="../show/SmartEngineGUI">?</a></span></p>',
|
'<a href="../show/SmartEngineGUI">?</a></span></p>',
|
||||||
@revision.display_content
|
PageRenderer.new(@revision).display_content
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_markdown
|
def test_markdown
|
||||||
|
@ -112,7 +172,8 @@ class RevisionTest < Test::Unit::TestCase
|
||||||
:author => Author.new('DavidHeinemeierHansson'))
|
:author => Author.new('DavidHeinemeierHansson'))
|
||||||
|
|
||||||
assert_equal "<tt>hello</tt> that <span class=\"newWikiWord\">Smart Engine GUI" +
|
assert_equal "<tt>hello</tt> that <span class=\"newWikiWord\">Smart Engine GUI" +
|
||||||
"<a href=\"../show/SmartEngineGUI\">?</a></span>\n\n", @revision.display_content
|
"<a href=\"../show/SmartEngineGUI\">?</a></span>\n\n",
|
||||||
|
PageRenderer.new(@revision).display_content
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_content_with_auto_links
|
def test_content_with_auto_links
|
||||||
|
@ -216,7 +277,7 @@ class RevisionTest < Test::Unit::TestCase
|
||||||
'<a class="existingWikiWord" href="MyWay.html">My Way</a> OverThere—see ' +
|
'<a class="existingWikiWord" href="MyWay.html">My Way</a> OverThere—see ' +
|
||||||
'<a class="existingWikiWord" href="SmartEngine.html">Smart Engine</a> in that ' +
|
'<a class="existingWikiWord" href="SmartEngine.html">Smart Engine</a> in that ' +
|
||||||
'<span class="newWikiWord">Smart Engine GUI</span></p>',
|
'<span class="newWikiWord">Smart Engine GUI</span></p>',
|
||||||
@revision.display_content_for_export
|
PageRenderer.new(@revision).display_content_for_export
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_double_replacing
|
def test_double_replacing
|
||||||
|
@ -225,23 +286,21 @@ class RevisionTest < Test::Unit::TestCase
|
||||||
"<a href=\"../show/VersionHistory\">?</a></span></p>\n\n\n\t<p>cry " +
|
"<a href=\"../show/VersionHistory\">?</a></span></p>\n\n\n\t<p>cry " +
|
||||||
'<span class="newWikiWord">Version History<a href="../show/VersionHistory">?</a>' +
|
'<span class="newWikiWord">Version History<a href="../show/VersionHistory">?</a>' +
|
||||||
'</span></p>',
|
'</span></p>',
|
||||||
@revision.display_content
|
PageRenderer.new(@revision).display_content
|
||||||
|
|
||||||
@revision.clear_display_cache
|
|
||||||
|
|
||||||
@revision.content = "f\r\nVersionHistory\r\n\r\ncry VersionHistory"
|
@revision.content = "f\r\nVersionHistory\r\n\r\ncry VersionHistory"
|
||||||
assert_equal "<p>f<br /><span class=\"newWikiWord\">Version History" +
|
assert_equal "<p>f<br /><span class=\"newWikiWord\">Version History" +
|
||||||
"<a href=\"../show/VersionHistory\">?</a></span></p>\n\n\n\t<p>cry " +
|
"<a href=\"../show/VersionHistory\">?</a></span></p>\n\n\n\t<p>cry " +
|
||||||
"<span class=\"newWikiWord\">Version History<a href=\"../show/VersionHistory\">?</a>" +
|
"<span class=\"newWikiWord\">Version History<a href=\"../show/VersionHistory\">?</a>" +
|
||||||
"</span></p>",
|
"</span></p>",
|
||||||
@revision.display_content
|
PageRenderer.new(@revision).display_content
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_difficult_wiki_words
|
def test_difficult_wiki_words
|
||||||
@revision.content = "[[It's just awesome GUI!]]"
|
@revision.content = "[[It's just awesome GUI!]]"
|
||||||
assert_equal "<p><span class=\"newWikiWord\">It's just awesome GUI!" +
|
assert_equal "<p><span class=\"newWikiWord\">It's just awesome GUI!" +
|
||||||
"<a href=\"../show/It%27s+just+awesome+GUI%21\">?</a></span></p>",
|
"<a href=\"../show/It%27s+just+awesome+GUI%21\">?</a></span></p>",
|
||||||
@revision.display_content
|
PageRenderer.new(@revision).display_content
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_revisions_diff
|
def test_revisions_diff
|
||||||
|
@ -252,7 +311,7 @@ class RevisionTest < Test::Unit::TestCase
|
||||||
|
|
||||||
assert_equal "<p>What a <del class=\"diffmod\">blue </del><ins class=\"diffmod\">red " +
|
assert_equal "<p>What a <del class=\"diffmod\">blue </del><ins class=\"diffmod\">red " +
|
||||||
"</ins>and lovely <del class=\"diffmod\">morning</del><ins class=\"diffmod\">morning " +
|
"</ins>and lovely <del class=\"diffmod\">morning</del><ins class=\"diffmod\">morning " +
|
||||||
"today</ins></p>", @page.revisions.last.display_diff
|
"today</ins></p>", PageRenderer.new(@page.revisions.last).display_diff
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_link_to_file
|
def test_link_to_file
|
||||||
|
@ -310,8 +369,22 @@ class RevisionTest < Test::Unit::TestCase
|
||||||
"!http://google.com!\r\nss")
|
"!http://google.com!\r\nss")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def add_sample_pages
|
||||||
|
@in_love = @web.add_page('EverBeenInLove', 'Who am I me',
|
||||||
|
Time.local(2004, 4, 4, 16, 50), 'DavidHeinemeierHansson')
|
||||||
|
@hated = @web.add_page('EverBeenHated', 'I am me EverBeenHated',
|
||||||
|
Time.local(2004, 4, 4, 16, 51), 'DavidHeinemeierHansson')
|
||||||
|
end
|
||||||
|
|
||||||
def assert_markup_parsed_as(expected_output, input)
|
def assert_markup_parsed_as(expected_output, input)
|
||||||
revision = Revision.new(:page => @page, :content => input, :author => Author.new('AnAuthor'))
|
revision = Revision.new(:page => @page, :content => input, :author => Author.new('AnAuthor'))
|
||||||
assert_equal expected_output, revision.display_content, 'Textile output not as expected'
|
assert_equal expected_output, PageRenderer.new(revision).display_content, 'Rendering output not as expected'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def rendered_content(page)
|
||||||
|
PageRenderer.new(page.revisions.last).display_content
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
|
@ -7,21 +7,6 @@ class WebTest < Test::Unit::TestCase
|
||||||
@web = webs(:instiki)
|
@web = webs(:instiki)
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_wiki_word_linking
|
|
||||||
@web.add_page('SecondPage', 'Yo, yo. Have you EverBeenHated',
|
|
||||||
Time.now, 'DavidHeinemeierHansson')
|
|
||||||
|
|
||||||
assert_equal('<p>Yo, yo. Have you <span class="newWikiWord">Ever Been Hated' +
|
|
||||||
'<a href="../show/EverBeenHated">?</a></span></p>',
|
|
||||||
@web.page("SecondPage").display_content)
|
|
||||||
|
|
||||||
@web.add_page('EverBeenHated', 'Yo, yo. Have you EverBeenHated', Time.now,
|
|
||||||
'DavidHeinemeierHansson')
|
|
||||||
assert_equal('<p>Yo, yo. Have you <a class="existingWikiWord" ' +
|
|
||||||
'href="../show/EverBeenHated">Ever Been Hated</a></p>',
|
|
||||||
@web.page("SecondPage").display_content)
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_pages_by_revision
|
def test_pages_by_revision
|
||||||
add_sample_pages
|
add_sample_pages
|
||||||
assert_equal 'EverBeenHated', @web.select.by_revision.first.name
|
assert_equal 'EverBeenHated', @web.select.by_revision.first.name
|
||||||
|
@ -47,52 +32,6 @@ class WebTest < Test::Unit::TestCase
|
||||||
assert_equal 1, @web.pages(true).length
|
assert_equal 1, @web.pages(true).length
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_make_link
|
|
||||||
add_sample_pages
|
|
||||||
|
|
||||||
existing_page_wiki_url =
|
|
||||||
'<a class="existingWikiWord" href="../show/EverBeenInLove">Ever Been In Love</a>'
|
|
||||||
existing_page_published_url =
|
|
||||||
'<a class="existingWikiWord" href="../published/EverBeenInLove">Ever Been In Love</a>'
|
|
||||||
existing_page_static_url =
|
|
||||||
'<a class="existingWikiWord" href="EverBeenInLove.html">Ever Been In Love</a>'
|
|
||||||
new_page_wiki_url =
|
|
||||||
'<span class="newWikiWord">Unknown Word<a href="../show/UnknownWord">?</a></span>'
|
|
||||||
new_page_published_url =
|
|
||||||
new_page_static_url =
|
|
||||||
'<span class="newWikiWord">Unknown Word</span>'
|
|
||||||
|
|
||||||
# no options
|
|
||||||
assert_equal existing_page_wiki_url, @web.make_link('EverBeenInLove')
|
|
||||||
|
|
||||||
# :mode => :export
|
|
||||||
assert_equal existing_page_static_url, @web.make_link('EverBeenInLove', nil, :mode => :export)
|
|
||||||
|
|
||||||
# :mode => :publish
|
|
||||||
assert_equal existing_page_published_url,
|
|
||||||
@web.make_link('EverBeenInLove', nil, :mode => :publish)
|
|
||||||
|
|
||||||
# new page, no options
|
|
||||||
assert_equal new_page_wiki_url, @web.make_link('UnknownWord')
|
|
||||||
|
|
||||||
# new page, :mode => :export
|
|
||||||
assert_equal new_page_static_url, @web.make_link('UnknownWord', nil, :mode => :export)
|
|
||||||
|
|
||||||
# new page, :mode => :publish
|
|
||||||
assert_equal new_page_published_url, @web.make_link('UnknownWord', nil, :mode => :publish)
|
|
||||||
|
|
||||||
# Escaping special characters in the name
|
|
||||||
assert_equal(
|
|
||||||
'<span class="newWikiWord">Smith & Wesson<a href="../show/Smith+%26+Wesson">?</a></span>',
|
|
||||||
@web.make_link('Smith & Wesson'))
|
|
||||||
|
|
||||||
# optionally using text as the link text
|
|
||||||
assert_equal(
|
|
||||||
existing_page_published_url.sub(/>Ever Been In Love</, ">Haven't you ever been in love?<"),
|
|
||||||
@web.make_link('EverBeenInLove', "Haven't you ever been in love?", :mode => :publish))
|
|
||||||
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_initialize
|
def test_initialize
|
||||||
web = Web.new(:name => 'Wiki2', :address => 'wiki2', :password => '123')
|
web = Web.new(:name => 'Wiki2', :address => 'wiki2', :password => '123')
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue