diff --git a/app/models/chunks/chunk.rb b/app/models/chunks/chunk.rb
index d374eb63..efd7ecfe 100755
--- a/app/models/chunks/chunk.rb
+++ b/app/models/chunks/chunk.rb
@@ -18,21 +18,30 @@ module Chunk
# in this content with its mask.
def self.apply_to(content)
content.gsub!( self.pattern ) do |match|
- content.chunks << self.new($~)
- content.chunks.last.mask(content)
+ new_chunk = self.new($~)
+ content.chunks << new_chunk
+ new_chunk.mask(content)
end
end
-
- def pre_mask()
- "chunk#{self.object_id}start "
+
+ def pre_mask
+ "chunk#{self.object_id}#{self.class.to_s.delete(':').downcase}start"
end
- def post_mask()
- " chunk#{self.object_id}end"
+ def post_mask
+ "chunk#{self.object_id}end"
end
+ def bracketing_mask(content)
+ "#{pre_mask} #{content} #{post_mask}"
+ end
+
+ def bracketing_mask_regexp
+ Regexp.new("#{pre_mask} (.*)[ \n]#{post_mask}")
+ end
+
def mask(content)
- "chunk#{self.object_id}chunk"
+ "chunk#{self.object_id}#{self.class.to_s.delete(':').downcase}chunk"
end
def revert(content)
diff --git a/app/models/chunks/wiki.rb b/app/models/chunks/wiki.rb
index f1a79d05..673deaa4 100755
--- a/app/models/chunks/wiki.rb
+++ b/app/models/chunks/wiki.rb
@@ -38,10 +38,13 @@ module WikiChunk
# By default, no escaped text
def escaped_text() nil end
- # Replace link with a mask, but if the word is escaped, then don't replace it
- def mask(content) escaped_text || "#{pre_mask}#{link_text}#{post_mask}" end
+ # FIXME: do not use the bracketing mask - URI chunk thinks that 'index.jpg'
+ # contains URL http://index.jp
- def regexp() /#{pre_mask}(.*)#{post_mask}/ end
+ # Replace link with a mask, but if the word is escaped, then don't replace it
+ def mask(content) escaped_text || bracketing_mask(link_text) end
+
+ def regexp() bracketing_mask_regexp end
def revert(content) content.sub!(regexp, text) end
diff --git a/app/models/page.rb b/app/models/page.rb
index bb4e24db..4773add2 100755
--- a/app/models/page.rb
+++ b/app/models/page.rb
@@ -7,7 +7,8 @@ require 'chunks/wiki'
class Page
include PageLock
- attr_reader :name, :revisions, :web
+ attr_reader :name, :web
+ attr_accessor :revisions
def initialize(web, name, content, created_at, author)
@web, @name, @revisions = web, name, []
diff --git a/app/models/web.rb b/app/models/web.rb
index 21e977be..a009afb2 100755
--- a/app/models/web.rb
+++ b/app/models/web.rb
@@ -7,9 +7,11 @@ require "zip/zip"
class Web
attr_accessor :name, :address, :password, :markup, :color, :safe_mode, :pages
attr_accessor :additional_style, :published, :brackets_only, :count_pages
- def initialize(name, address, password = nil)
+
+ def initialize(parent_wiki, name, address, password = nil)
@name, @address, @password, @safe_mode = name, address, password, false
@pages = {}
+ @wiki = parent_wiki
# assign default values
@color = '008B26'
@@ -44,28 +46,75 @@ class Web
# on the render mode in options and whether the page exists
# in the this web.
def make_link(name, text = nil, options = {})
- page = pages[name]
text = text || WikiWords.separate(name)
- link = CGI.escape(name)
- link_type = options[:link_type] || :show
-
- case options[:mode]
- when :export
- if page then "#{text}"
- else "#{text}" end
- when :publish
- if page then "#{text}"
- else "#{text}" end
- else
- if page
- "#{text}"
- else
- "#{text}?"
- end
+ mode = options[:mode]
+ link_type = options[:link_type] || 'show'
+ case link_type
+ when 'show'
+ make_page_link(mode, name, text)
+ when 'file'
+ make_file_link(mode, name, text)
+ when 'pic'
+ make_pic_link(mode, name, text)
+ else
+ raise "Unknown link type: #{link_type}"
end
-
end
+ def make_page_link(mode, name, text)
+ link = CGI.escape(name)
+ case mode
+ when :export
+ if has_page?(name) then "#{text}"
+ else "#{text}" end
+ when :publish
+ if has_page?(name) then "#{text}"
+ else "#{text}" end
+ else
+ if has_page?(name)
+ "#{text}"
+ else
+ "#{text}?"
+ end
+ end
+ end
+
+ def make_file_link(mode, name, text)
+ link = CGI.escape(name)
+ case mode
+ when :export
+ if has_file?(name) then "#{text}"
+ else "#{text}" end
+ when :publish
+ if has_file?(name) then "#{text}"
+ else "#{text}" end
+ else
+ if has_file?(name)
+ "#{text}"
+ else
+ "#{text}?"
+ end
+ end
+ end
+
+ def make_pic_link(mode, name, text)
+ link = CGI.escape(name)
+ case mode
+ when :export
+ if has_file?(name) then ""
+ else "
" end
+ else
+ "
"
+ end
+ end
+
+ def has_page?(name)
+ pages[name]
+ end
+
+ def has_file?(name)
+ wiki.file_yard(self).has_file?(name)
+ end
# Clears the display cache for all the pages with references to
def refresh_pages_with_references(page_name)
@@ -88,4 +137,9 @@ class Web
def page_names
pages.keys
end
+
+ # This ensures compatibility with 0.9 storages
+ def wiki
+ @wiki ||= WikiService.instance
+ end
end
\ No newline at end of file
diff --git a/app/models/wiki_content.rb b/app/models/wiki_content.rb
index 7ef5d790..b596b2ff 100755
--- a/app/models/wiki_content.rb
+++ b/app/models/wiki_content.rb
@@ -66,11 +66,12 @@ class WikiContent < String
@options[:pre_engine_actions].delete(WikiChunk::Word) if @web.brackets_only
super(@revision.content)
-
+
begin
render!(@options[:pre_engine_actions] + [@options[:engine]] + @options[:post_engine_actions])
- rescue => e
- @rendered = e.message
+# FIXME this is where all the parsing problems were shoved under the carpet
+# rescue => e
+# @rendered = e.message
end
end
diff --git a/app/models/wiki_service.rb b/app/models/wiki_service.rb
index 9bd242fb..2c52a146 100755
--- a/app/models/wiki_service.rb
+++ b/app/models/wiki_service.rb
@@ -18,7 +18,7 @@ module AbstractWikiService
end
def create_web(name, address, password = nil)
- @webs[address] = Web.new(name, address, password) unless @webs[address]
+ @webs[address] = Web.new(self, name, address, password) unless @webs[address]
end
def delete_web(address)
diff --git a/test/unit/page_test.rb b/test/unit/page_test.rb
index 99ef4a1c..8e965a50 100755
--- a/test/unit/page_test.rb
+++ b/test/unit/page_test.rb
@@ -7,7 +7,7 @@ require 'page'
class PageTest < Test::Unit::TestCase
class MockWeb < Web
- def initialize() super('test','test') end
+ def initialize() super(nil, 'test','test') end
def [](wiki_word) %w( MyWay ThatWay SmartEngine ).include?(wiki_word) end
def refresh_pages_with_references(name) end
end
diff --git a/test/unit/revision_test.rb b/test/unit/revision_test.rb
index 6f7e2bf3..2bb60c94 100755
--- a/test/unit/revision_test.rb
+++ b/test/unit/revision_test.rb
@@ -4,28 +4,16 @@ require File.dirname(__FILE__) + '/../test_helper'
require 'web'
require 'revision'
-class WebStub < Web
- def initialize(); end
- attr_accessor :markup
- def pages() PagesStub.new end
- def safe_mode() false end
-end
-class PagesStub
- def [](wiki_word) %w( MyWay ThatWay SmartEngine ).include?(wiki_word) end
-end
-class PageStub
- attr_accessor :web, :revisions
- def name() 'page' end
-end
-
class RevisionTest < Test::Unit::TestCase
def setup
- @web = WebStub.new
+ setup_test_wiki
@web.markup = :textile
- @page = PageStub.new
- @page.web = @web
+ @page = @wiki.read_page('wiki1', 'HomePage')
+ ['MyWay', 'SmartEngine', 'ThatWay'].each do |page|
+ @wiki.write_page('wiki1', page, page, Time.now, 'Me')
+ end
@revision = Revision.new(@page, 1,
'HisWay would be MyWay in kinda ThatWay in HisWay though MyWay \\OverThere -- ' +
@@ -218,8 +206,11 @@ class RevisionTest < Test::Unit::TestCase
def test_link_to_pic
assert_markup_parsed_as(
- '
Square?
', + '