[BREAKS BUILD] Links to pictures. Problem is, URIChunk thinks that index.jpg is a hyperlink to http://index.jp.

Also, commented out the code that was hiding rendering errors. This should be done at a different level.
This commit is contained in:
Alexey Verkhovsky 2005-01-23 03:27:45 +00:00
parent 1d82582c3b
commit d6fe54f4ad
9 changed files with 114 additions and 55 deletions

View file

@ -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)

View file

@ -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

View file

@ -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, []

View file

@ -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
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
case options[:mode]
def make_page_link(mode, name, text)
link = CGI.escape(name)
case mode
when :export
if page then "<a class=\"existingWikiWord\" href=\"#{link}.html\">#{text}</a>"
if has_page?(name) then "<a class=\"existingWikiWord\" href=\"#{link}.html\">#{text}</a>"
else "<span class=\"newWikiWord\">#{text}</span>" end
when :publish
if page then "<a class=\"existingWikiWord\" href=\"../published/#{link}\">#{text}</a>"
if has_page?(name) then "<a class=\"existingWikiWord\" href=\"../published/#{link}\">#{text}</a>"
else "<span class=\"newWikiWord\">#{text}</span>" end
else
if page
"<a class=\"existingWikiWord\" href=\"../#{link_type}/#{link}\">#{text}</a>"
if has_page?(name)
"<a class=\"existingWikiWord\" href=\"../show/#{link}\">#{text}</a>"
else
"<span class=\"newWikiWord\">#{text}<a href=\"../#{link_type}/#{link}\">?</a></span>"
"<span class=\"newWikiWord\">#{text}<a href=\"../show/#{link}\">?</a></span>"
end
end
end
def make_file_link(mode, name, text)
link = CGI.escape(name)
case mode
when :export
if has_file?(name) then "<a class=\"existingWikiWord\" href=\"#{link}.html\">#{text}</a>"
else "<span class=\"newWikiWord\">#{text}</span>" end
when :publish
if has_file?(name) then "<a class=\"existingWikiWord\" href=\"../published/#{link}\">#{text}</a>"
else "<span class=\"newWikiWord\">#{text}</span>" end
else
if has_file?(name)
"<a class=\"existingWikiWord\" href=\"../file/#{link}\">#{text}</a>"
else
"<span class=\"newWikiWord\">#{text}<a href=\"../file/#{link}\">?</a></span>"
end
end
end
def make_pic_link(mode, name, text)
link = CGI.escape(name)
case mode
when :export
if has_file?(name) then "<img alt=\"#{text}\" src=\"#{link}\" />"
else "<img alt=\"#{text}\" src=\"no image\" />" end
else
"<img alt=\"#{text}\" src=\"../pic/#{link}\" />"
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

View file

@ -69,8 +69,9 @@ class WikiContent < String
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

View file

@ -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)

View file

@ -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

View file

@ -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(
'<p><span class="newWikiWord">Square<a href="../pic/square.jpg">?</a></span></p>',
'<p><img alt="Square" src="../pic/square.jpg" /></p>',
'[[square.jpg|Square:pic]]')
assert_markup_parsed_as(
'<p><img alt="square.jpg" src="../pic/square.jpg" /></p>',
'[[square.jpg:pic]]')
end
# TODO Remove the leading underscores from this test when upgrading to RedCloth 3.0.1;

View file

@ -5,7 +5,7 @@ require 'wiki_service'
class WebTest < Test::Unit::TestCase
def setup
@web = Web.new 'Instiki', 'instiki'
@web = Web.new nil, 'Instiki', 'instiki'
end
def test_wiki_word_linking