-
<%= h page.plain_name %>
<% unless @hide_description %>
- <%= h page.display_content %>
+ <%= h rendered_content(page) %>
<% end %>
<%= page.revised_at.getgm.strftime "%a, %d %b %Y %H:%M:%S Z" %>
<%= url_for :only_path => false, :web => @web_name, :action => @link_action, :id => page.name %>
diff --git a/config/environments/development.rb b/config/environments/development.rb
index 3f0868e6..d214c666 100644
--- a/config/environments/development.rb
+++ b/config/environments/development.rb
@@ -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.perform_caching = false
+ActionController::Base.perform_caching = false
+
+# The breakpoint server port that script/breakpointer connects to.
BREAKPOINT_SERVER_PORT = 42531
diff --git a/lib/page_renderer.rb b/lib/page_renderer.rb
new file mode 100644
index 00000000..c9887404
--- /dev/null
+++ b/lib/page_renderer.rb
@@ -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
+
Markup engine has failed to render this page, raising the following error:
+ #{message}
+ #{self.content}
+ EOL
+ clear_display_cache
+ raise e
+ end
+ end
+
+ protected
+
+end
\ No newline at end of file
diff --git a/test/functional/file_controller_test.rb b/test/functional/file_controller_test.rb
index a7023aff..01586b09 100755
--- a/test/functional/file_controller_test.rb
+++ b/test/functional/file_controller_test.rb
@@ -96,8 +96,8 @@ class FileControllerTest < Test::Unit::TestCase
@wiki.revise_page('wiki1', 'HomePage', '[[instiki-e2e.txt:file]]', Time.now, 'AnonymousBrave')
assert_equal "instiki-e2e.txt" +
"?
",
- @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
r = process 'file', 'web' => 'wiki1', 'id' => 'instiki-e2e.txt'
assert_success
@@ -114,7 +114,7 @@ class FileControllerTest < Test::Unit::TestCase
@home = Page.find(@home.id)
assert_equal "" +
"instiki-e2e.txt
",
- @home.display_content
+ PageRenderer.new(@home.revisions.last).display_content
end
def test_uploads_blocking
diff --git a/test/functional/wiki_controller_test.rb b/test/functional/wiki_controller_test.rb
index 57329061..095a74c1 100755
--- a/test/functional/wiki_controller_test.rb
+++ b/test/functional/wiki_controller_test.rb
@@ -364,7 +364,7 @@ class WikiControllerTest < Test::Unit::TestCase
def test_rss_with_content
r = process 'rss_with_content', 'web' => 'wiki1'
-
+
assert_success
pages = r.template_objects['pages_by_revision']
assert_equal [@elephant, @oak, pages(:no_wiki_word), pages(:that_way), pages(:smart_engine), pages(:my_way), pages(:first_page), @home], pages,
diff --git a/test/unit/revision_test.rb b/test/unit/page_renderer_test.rb
similarity index 73%
rename from test/unit/revision_test.rb
rename to test/unit/page_renderer_test.rb
index f22bfd5d..1c71449f 100644
--- a/test/unit/revision_test.rb
+++ b/test/unit/page_renderer_test.rb
@@ -1,317 +1,390 @@
-require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
-
-class RevisionTest < Test::Unit::TestCase
- fixtures :webs, :pages, :revisions, :system
-
- def setup
- @wiki = Wiki.new
- @web = webs(:test_wiki)
- @page = pages(:home_page)
- @revision = revisions(:home_page_second_revision)
- end
-
- def test_wiki_words
- assert_equal %w( HisWay MyWay SmartEngine SmartEngineGUI ThatWay ), @revision.wiki_words.sort
-
- @wiki.write_page('wiki1', 'NoWikiWord', 'hey you!', Time.now, 'Me')
- assert_equal [], @wiki.read_page('wiki1', 'NoWikiWord').wiki_words
- end
-
- def test_existing_pages
- assert_equal %w( MyWay SmartEngine ThatWay ), @revision.existing_pages.sort
- end
-
- def test_unexisting_pages
- assert_equal %w( HisWay SmartEngineGUI ), @revision.unexisting_pages.sort
- end
-
- def test_content_with_wiki_links
- assert_equal 'His Way? ' +
- 'would be My Way in kinda ' +
- 'That Way in ' +
- 'His Way? ' +
- 'though My Way OverThere—see ' +
- 'Smart Engine in that ' +
- 'Smart Engine GUI' +
- '?
',
- @revision.display_content
- end
-
- def test_markdown
- set_web_property :markup, :markdown
-
- assert_markup_parsed_as(
- %{My Headline
\n\nthat } +
- %{Smart Engine GUI?
},
- "My Headline\n===========\n\nthat SmartEngineGUI")
-
- code_block = [
- 'This is a code block:',
- '',
- ' def a_method(arg)',
- ' return ThatWay',
- '',
- 'Nice!'
- ].join("\n")
-
- assert_markup_parsed_as(
- %{This is a code block:
\n\ndef a_method(arg)\n} +
- %{return ThatWay\n
\n\nNice!
},
- code_block)
- end
-
- def test_markdown_hyperlink_with_slash
- # in response to a bug, see http://dev.instiki.org/attachment/ticket/177
- set_web_property :markup, :markdown
-
- assert_markup_parsed_as(
- 'text
',
- '[text](http://example/with/slash)')
- end
-
- def test_mixed_formatting
- textile_and_markdown = [
- 'Markdown heading',
- '================',
- '',
- 'h2. Textile heading',
- '',
- '*some* **text** _with_ -styles-',
- '',
- '* list 1',
- '* list 2'
- ].join("\n")
-
- set_web_property :markup, :markdown
- assert_markup_parsed_as(
- "Markdown heading
\n\n" +
- "h2. Textile heading
\n\n" +
- "some text with -styles-
\n\n" +
- "",
- textile_and_markdown)
-
- set_web_property :markup, :textile
- assert_markup_parsed_as(
- "Markdown heading
================
\n\n\n\tTextile heading
" +
- "\n\n\n\tsome text with styles
" +
- "\n\n\n\t\n\t- list 1
\n\t\t- list 2
\n\t
",
- textile_and_markdown)
-
- set_web_property :markup, :mixed
- assert_markup_parsed_as(
- "Markdown heading
\n\n\n\tTextile heading
\n\n\n\t" +
- "some text with styles
\n\n\n\t" +
- "\n\t- list 1
\n\t\t- list 2
\n\t
",
- textile_and_markdown)
- end
-
- def test_rdoc
- set_web_property :markup, :rdoc
-
- @revision = Revision.new(:page => @page, :content => '+hello+ that SmartEngineGUI',
- :author => Author.new('DavidHeinemeierHansson'))
-
- assert_equal "hello that Smart Engine GUI" +
- "?\n\n", @revision.display_content
- end
-
- def test_content_with_auto_links
- assert_markup_parsed_as(
- 'http://www.loudthinking.com/ ' +
- 'points to That Way from ' +
- 'david@loudthinking.com
',
- 'http://www.loudthinking.com/ points to ThatWay from david@loudthinking.com')
-
- end
-
- def test_content_with_aliased_links
- assert_markup_parsed_as(
- 'Would a clever motor' +
- ' go by any other name?
',
- 'Would a [[SmartEngine|clever motor]] go by any other name?')
- end
-
- def test_content_with_wikiword_in_em
- assert_markup_parsed_as(
- 'should we go ' +
- 'That Way or This Way?' +
- '
',
- '_should we go ThatWay or ThisWay _')
- end
-
- def test_content_with_wikiword_in_tag
- assert_markup_parsed_as(
- 'That is some Stylish Emphasis
',
- 'That is some Stylish Emphasis')
- end
-
- def test_content_with_escaped_wikiword
- # there should be no wiki link
- assert_markup_parsed_as('WikiWord
', '\WikiWord')
- end
-
- def test_content_with_pre_blocks
- assert_markup_parsed_as(
- 'A class SmartEngine end
would not mark up
CodeBlocks
',
- 'A class SmartEngine end
would not mark up CodeBlocks
')
- end
-
- def test_content_with_autolink_in_parentheses
- assert_markup_parsed_as(
- 'The W3C body (' +
- 'http://www.w3c.org) sets web standards
',
- 'The W3C body (http://www.w3c.org) sets web standards')
- end
-
- def test_content_with_link_in_parentheses
- assert_markup_parsed_as(
- '(What is a wiki?)
',
- '("What is a wiki?":http://wiki.org/wiki.cgi?WhatIsWiki)')
- end
-
- def test_content_with_image_link
- assert_markup_parsed_as(
- 'This
is a Textile image link.
',
- 'This !http://hobix.com/sample.jpg! is a Textile image link.')
- end
-
- def test_content_with_inlined_img_tag
- assert_markup_parsed_as(
- 'This
is an inline image link.
',
- 'This
is an inline image link.')
-
- assert_markup_parsed_as(
- 'This
is an inline image link.
',
- 'This
is an inline image link.')
- end
-
- def test_nowiki_tag
- assert_markup_parsed_as(
- 'Do not mark up [[this text]] or http://www.thislink.com.
',
- 'Do not mark up [[this text]] ' +
- 'or http://www.thislink.com.')
- end
-
- def test_multiline_nowiki_tag
- assert_markup_parsed_as(
- "Do not mark \n up [[this text]] \nand http://this.url.com but markup " +
- 'this?
',
- "Do not mark \n up [[this text]] \n" +
- "and http://this.url.com but markup [[this]]")
- end
-
- def test_content_with_bracketted_wiki_word
- set_web_property :brackets_only, true
- assert_markup_parsed_as(
- 'This is a WikiWord and a tricky name ' +
- 'Sperberg-McQueen?.
',
- 'This is a WikiWord and a tricky name [[Sperberg-McQueen]].')
- end
-
- def test_content_for_export
- assert_equal 'His Way would be ' +
- 'My Way in kinda ' +
- 'That Way in ' +
- 'His Way though ' +
- 'My Way OverThere—see ' +
- 'Smart Engine in that ' +
- 'Smart Engine GUI
',
- @revision.display_content_for_export
- end
-
- def test_double_replacing
- @revision.content = "VersionHistory\r\n\r\ncry VersionHistory"
- assert_equal 'Version History' +
- "?
\n\n\n\tcry " +
- 'Version History?' +
- '
',
- @revision.display_content
-
- @revision.clear_display_cache
-
- @revision.content = "f\r\nVersionHistory\r\n\r\ncry VersionHistory"
- assert_equal "f
Version History" +
- "?
\n\n\n\tcry " +
- "Version History?" +
- "
",
- @revision.display_content
- end
-
- def test_difficult_wiki_words
- @revision.content = "[[It's just awesome GUI!]]"
- assert_equal "It's just awesome GUI!" +
- "?
",
- @revision.display_content
- end
-
- def test_revisions_diff
- Revision.create(:page => @page, :content => 'What a blue and lovely morning',
- :author => Author.new('DavidHeinemeierHansson'), :revised_at => Time.now)
- Revision.create(:page => @page, :content => 'What a red and lovely morning today',
- :author => Author.new('DavidHeinemeierHansson'), :revised_at => Time.now)
-
- assert_equal "What a blue red " +
- "and lovely morningmorning " +
- "today
", @page.revisions.last.display_diff
- end
-
- def test_link_to_file
- assert_markup_parsed_as(
- 'doc.pdf?
',
- '[[doc.pdf:file]]')
- end
-
- def test_link_to_pic
- FileUtils.mkdir_p "#{RAILS_ROOT}/storage/test/wiki1"
- FileUtils.rm(Dir["#{RAILS_ROOT}/storage/test/wiki1/*"])
- @wiki.file_yard(@web).upload_file('square.jpg', StringIO.new(''))
- assert_markup_parsed_as(
- '![Square](../pic/square.jpg)
',
- '[[square.jpg|Square:pic]]')
- assert_markup_parsed_as(
- '![square.jpg](../pic/square.jpg)
',
- '[[square.jpg:pic]]')
- end
-
- def test_link_to_non_existant_pic
- assert_markup_parsed_as(
- 'NonExistant?' +
- '
',
- '[[NonExistant.jpg|NonExistant:pic]]')
- assert_markup_parsed_as(
- 'NonExistant.jpg?' +
- '
',
- '[[NonExistant.jpg:pic]]')
- end
-
- def test_wiki_link_with_colon
- assert_markup_parsed_as(
- 'With:Colon?
',
- '[[With:Colon]]')
- end
-
- # TODO Remove the leading underscores from this test when upgrading to RedCloth 3.0.1;
- # also add a test for the "Unhappy Face" problem (another interesting RedCloth bug)
- def test_list_with_tildas
- list_with_tildas = <<-EOL
- * "a":~b
- * c~ d
- EOL
-
- assert_markup_parsed_as(
- "",
- list_with_tildas)
- end
-
- def test_textile_image_in_mixed_wiki
- set_web_property :markup, :mixed
- assert_markup_parsed_as(
- "
\nss
",
- "!http://google.com!\r\nss")
- end
-
- def assert_markup_parsed_as(expected_output, input)
- revision = Revision.new(:page => @page, :content => input, :author => Author.new('AnAuthor'))
- assert_equal expected_output, revision.display_content, 'Textile output not as expected'
- end
-end
+require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
+
+class PageRendererTest < Test::Unit::TestCase
+ fixtures :webs, :pages, :revisions, :system
+
+ def setup
+ @wiki = Wiki.new
+ @web = webs(:test_wiki)
+ @page = pages(:home_page)
+ @revision = revisions(:home_page_second_revision)
+ end
+
+ def test_wiki_word_linking
+ @web.add_page('SecondPage', 'Yo, yo. Have you EverBeenHated',
+ Time.now, 'DavidHeinemeierHansson')
+
+ assert_equal('Yo, yo. Have you Ever Been Hated' +
+ '?
',
+ rendered_content(@web.page("SecondPage")))
+
+ @web.add_page('EverBeenHated', 'Yo, yo. Have you EverBeenHated', Time.now,
+ 'DavidHeinemeierHansson')
+ assert_equal('Yo, yo. Have you Ever Been Hated
',
+ rendered_content(@web.page("SecondPage")))
+ end
+
+ def test_make_link
+ add_sample_pages
+
+ existing_page_wiki_url =
+ 'Ever Been In Love'
+ existing_page_published_url =
+ 'Ever Been In Love'
+ existing_page_static_url =
+ 'Ever Been In Love'
+ new_page_wiki_url =
+ 'Unknown Word?'
+ new_page_published_url = new_page_static_url = 'Unknown Word'
+
+ # 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(
+ 'Smith & Wesson?',
+ @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
+ assert_equal %w( HisWay MyWay SmartEngine SmartEngineGUI ThatWay ),
+ PageRenderer.new(@revision).wiki_words.sort
+
+ @wiki.write_page('wiki1', 'NoWikiWord', 'hey you!', Time.now, 'Me')
+ assert_equal [], PageRenderer.new(@wiki.read_page('wiki1', 'NoWikiWord').revisions.last).wiki_words
+ end
+
+ def test_existing_pages
+ assert_equal %w( MyWay SmartEngine ThatWay ), PageRenderer.new(@revision).existing_pages.sort
+ end
+
+ def test_unexisting_pages
+ assert_equal %w( HisWay SmartEngineGUI ), PageRenderer.new(@revision).unexisting_pages.sort
+ end
+
+ def test_content_with_wiki_links
+ assert_equal 'His Way? ' +
+ 'would be My Way in kinda ' +
+ 'That Way in ' +
+ 'His Way? ' +
+ 'though My Way OverThere—see ' +
+ 'Smart Engine in that ' +
+ 'Smart Engine GUI' +
+ '?
',
+ PageRenderer.new(@revision).display_content
+ end
+
+ def test_markdown
+ set_web_property :markup, :markdown
+
+ assert_markup_parsed_as(
+ %{My Headline
\n\nthat } +
+ %{Smart Engine GUI?
},
+ "My Headline\n===========\n\nthat SmartEngineGUI")
+
+ code_block = [
+ 'This is a code block:',
+ '',
+ ' def a_method(arg)',
+ ' return ThatWay',
+ '',
+ 'Nice!'
+ ].join("\n")
+
+ assert_markup_parsed_as(
+ %{This is a code block:
\n\ndef a_method(arg)\n} +
+ %{return ThatWay\n
\n\nNice!
},
+ code_block)
+ end
+
+ def test_markdown_hyperlink_with_slash
+ # in response to a bug, see http://dev.instiki.org/attachment/ticket/177
+ set_web_property :markup, :markdown
+
+ assert_markup_parsed_as(
+ 'text
',
+ '[text](http://example/with/slash)')
+ end
+
+ def test_mixed_formatting
+ textile_and_markdown = [
+ 'Markdown heading',
+ '================',
+ '',
+ 'h2. Textile heading',
+ '',
+ '*some* **text** _with_ -styles-',
+ '',
+ '* list 1',
+ '* list 2'
+ ].join("\n")
+
+ set_web_property :markup, :markdown
+ assert_markup_parsed_as(
+ "Markdown heading
\n\n" +
+ "h2. Textile heading
\n\n" +
+ "some text with -styles-
\n\n" +
+ "",
+ textile_and_markdown)
+
+ set_web_property :markup, :textile
+ assert_markup_parsed_as(
+ "Markdown heading
================
\n\n\n\tTextile heading
" +
+ "\n\n\n\tsome text with styles
" +
+ "\n\n\n\t\n\t- list 1
\n\t\t- list 2
\n\t
",
+ textile_and_markdown)
+
+ set_web_property :markup, :mixed
+ assert_markup_parsed_as(
+ "Markdown heading
\n\n\n\tTextile heading
\n\n\n\t" +
+ "some text with styles
\n\n\n\t" +
+ "\n\t- list 1
\n\t\t- list 2
\n\t
",
+ textile_and_markdown)
+ end
+
+ def test_rdoc
+ set_web_property :markup, :rdoc
+
+ @revision = Revision.new(:page => @page, :content => '+hello+ that SmartEngineGUI',
+ :author => Author.new('DavidHeinemeierHansson'))
+
+ assert_equal "hello that Smart Engine GUI" +
+ "?\n\n",
+ PageRenderer.new(@revision).display_content
+ end
+
+ def test_content_with_auto_links
+ assert_markup_parsed_as(
+ 'http://www.loudthinking.com/ ' +
+ 'points to That Way from ' +
+ 'david@loudthinking.com
',
+ 'http://www.loudthinking.com/ points to ThatWay from david@loudthinking.com')
+
+ end
+
+ def test_content_with_aliased_links
+ assert_markup_parsed_as(
+ 'Would a clever motor' +
+ ' go by any other name?
',
+ 'Would a [[SmartEngine|clever motor]] go by any other name?')
+ end
+
+ def test_content_with_wikiword_in_em
+ assert_markup_parsed_as(
+ 'should we go ' +
+ 'That Way or This Way?' +
+ '
',
+ '_should we go ThatWay or ThisWay _')
+ end
+
+ def test_content_with_wikiword_in_tag
+ assert_markup_parsed_as(
+ 'That is some Stylish Emphasis
',
+ 'That is some Stylish Emphasis')
+ end
+
+ def test_content_with_escaped_wikiword
+ # there should be no wiki link
+ assert_markup_parsed_as('WikiWord
', '\WikiWord')
+ end
+
+ def test_content_with_pre_blocks
+ assert_markup_parsed_as(
+ 'A class SmartEngine end
would not mark up
CodeBlocks
',
+ 'A class SmartEngine end
would not mark up CodeBlocks
')
+ end
+
+ def test_content_with_autolink_in_parentheses
+ assert_markup_parsed_as(
+ 'The W3C body (' +
+ 'http://www.w3c.org) sets web standards
',
+ 'The W3C body (http://www.w3c.org) sets web standards')
+ end
+
+ def test_content_with_link_in_parentheses
+ assert_markup_parsed_as(
+ '(What is a wiki?)
',
+ '("What is a wiki?":http://wiki.org/wiki.cgi?WhatIsWiki)')
+ end
+
+ def test_content_with_image_link
+ assert_markup_parsed_as(
+ 'This
is a Textile image link.
',
+ 'This !http://hobix.com/sample.jpg! is a Textile image link.')
+ end
+
+ def test_content_with_inlined_img_tag
+ assert_markup_parsed_as(
+ 'This
is an inline image link.
',
+ 'This
is an inline image link.')
+
+ assert_markup_parsed_as(
+ 'This
is an inline image link.
',
+ 'This
is an inline image link.')
+ end
+
+ def test_nowiki_tag
+ assert_markup_parsed_as(
+ 'Do not mark up [[this text]] or http://www.thislink.com.
',
+ 'Do not mark up [[this text]] ' +
+ 'or http://www.thislink.com.')
+ end
+
+ def test_multiline_nowiki_tag
+ assert_markup_parsed_as(
+ "Do not mark \n up [[this text]] \nand http://this.url.com but markup " +
+ 'this?
',
+ "Do not mark \n up [[this text]] \n" +
+ "and http://this.url.com but markup [[this]]")
+ end
+
+ def test_content_with_bracketted_wiki_word
+ set_web_property :brackets_only, true
+ assert_markup_parsed_as(
+ 'This is a WikiWord and a tricky name ' +
+ 'Sperberg-McQueen?.
',
+ 'This is a WikiWord and a tricky name [[Sperberg-McQueen]].')
+ end
+
+ def test_content_for_export
+ assert_equal 'His Way would be ' +
+ 'My Way in kinda ' +
+ 'That Way in ' +
+ 'His Way though ' +
+ 'My Way OverThere—see ' +
+ 'Smart Engine in that ' +
+ 'Smart Engine GUI
',
+ PageRenderer.new(@revision).display_content_for_export
+ end
+
+ def test_double_replacing
+ @revision.content = "VersionHistory\r\n\r\ncry VersionHistory"
+ assert_equal 'Version History' +
+ "?
\n\n\n\tcry " +
+ 'Version History?' +
+ '
',
+ PageRenderer.new(@revision).display_content
+
+ @revision.content = "f\r\nVersionHistory\r\n\r\ncry VersionHistory"
+ assert_equal "f
Version History" +
+ "?
\n\n\n\tcry " +
+ "Version History?" +
+ "
",
+ PageRenderer.new(@revision).display_content
+ end
+
+ def test_difficult_wiki_words
+ @revision.content = "[[It's just awesome GUI!]]"
+ assert_equal "It's just awesome GUI!" +
+ "?
",
+ PageRenderer.new(@revision).display_content
+ end
+
+ def test_revisions_diff
+ Revision.create(:page => @page, :content => 'What a blue and lovely morning',
+ :author => Author.new('DavidHeinemeierHansson'), :revised_at => Time.now)
+ Revision.create(:page => @page, :content => 'What a red and lovely morning today',
+ :author => Author.new('DavidHeinemeierHansson'), :revised_at => Time.now)
+
+ assert_equal "What a blue red " +
+ "and lovely morningmorning " +
+ "today
", PageRenderer.new(@page.revisions.last).display_diff
+ end
+
+ def test_link_to_file
+ assert_markup_parsed_as(
+ 'doc.pdf?
',
+ '[[doc.pdf:file]]')
+ end
+
+ def test_link_to_pic
+ FileUtils.mkdir_p "#{RAILS_ROOT}/storage/test/wiki1"
+ FileUtils.rm(Dir["#{RAILS_ROOT}/storage/test/wiki1/*"])
+ @wiki.file_yard(@web).upload_file('square.jpg', StringIO.new(''))
+ assert_markup_parsed_as(
+ '![Square](../pic/square.jpg)
',
+ '[[square.jpg|Square:pic]]')
+ assert_markup_parsed_as(
+ '![square.jpg](../pic/square.jpg)
',
+ '[[square.jpg:pic]]')
+ end
+
+ def test_link_to_non_existant_pic
+ assert_markup_parsed_as(
+ 'NonExistant?' +
+ '
',
+ '[[NonExistant.jpg|NonExistant:pic]]')
+ assert_markup_parsed_as(
+ 'NonExistant.jpg?' +
+ '
',
+ '[[NonExistant.jpg:pic]]')
+ end
+
+ def test_wiki_link_with_colon
+ assert_markup_parsed_as(
+ 'With:Colon?
',
+ '[[With:Colon]]')
+ end
+
+ # TODO Remove the leading underscores from this test when upgrading to RedCloth 3.0.1;
+ # also add a test for the "Unhappy Face" problem (another interesting RedCloth bug)
+ def test_list_with_tildas
+ list_with_tildas = <<-EOL
+ * "a":~b
+ * c~ d
+ EOL
+
+ assert_markup_parsed_as(
+ "",
+ list_with_tildas)
+ end
+
+ def test_textile_image_in_mixed_wiki
+ set_web_property :markup, :mixed
+ assert_markup_parsed_as(
+ "
\nss
",
+ "!http://google.com!\r\nss")
+ 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)
+ revision = Revision.new(:page => @page, :content => input, :author => Author.new('AnAuthor'))
+ assert_equal expected_output, PageRenderer.new(revision).display_content, 'Rendering output not as expected'
+ end
+
+ def rendered_content(page)
+ PageRenderer.new(page.revisions.last).display_content
+ end
+
+end
\ No newline at end of file
diff --git a/test/unit/web_test.rb b/test/unit/web_test.rb
index 7e91bbed..bfa6edd7 100644
--- a/test/unit/web_test.rb
+++ b/test/unit/web_test.rb
@@ -7,21 +7,6 @@ class WebTest < Test::Unit::TestCase
@web = webs(:instiki)
end
- def test_wiki_word_linking
- @web.add_page('SecondPage', 'Yo, yo. Have you EverBeenHated',
- Time.now, 'DavidHeinemeierHansson')
-
- assert_equal('Yo, yo. Have you Ever Been Hated' +
- '?
',
- @web.page("SecondPage").display_content)
-
- @web.add_page('EverBeenHated', 'Yo, yo. Have you EverBeenHated', Time.now,
- 'DavidHeinemeierHansson')
- assert_equal('Yo, yo. Have you Ever Been Hated
',
- @web.page("SecondPage").display_content)
- end
-
def test_pages_by_revision
add_sample_pages
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
end
- def test_make_link
- add_sample_pages
-
- existing_page_wiki_url =
- 'Ever Been In Love'
- existing_page_published_url =
- 'Ever Been In Love'
- existing_page_static_url =
- 'Ever Been In Love'
- new_page_wiki_url =
- 'Unknown Word?'
- new_page_published_url =
- new_page_static_url =
- 'Unknown Word'
-
- # 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(
- 'Smith & Wesson?',
- @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
web = Web.new(:name => 'Wiki2', :address => 'wiki2', :password => '123')
@@ -129,7 +68,7 @@ class WebTest < Test::Unit::TestCase
@web.pages(true)
assert_equal [home], @web.select.pages_that_link_to('AnotherPage')
end
-
+
def test_orphaned_pages
add_sample_pages
home = @web.add_page('HomePage',