Wiki links to files point to the appropriate actions (file, pic)
This commit is contained in:
parent
c30989c7eb
commit
e6c32bafc6
|
@ -36,7 +36,7 @@ module Chunk
|
||||||
end
|
end
|
||||||
|
|
||||||
def revert(content)
|
def revert(content)
|
||||||
content.sub!( Regexp.new(mask(content)), text )
|
content.sub!( Regexp.new(mask(content)), text )
|
||||||
end
|
end
|
||||||
|
|
||||||
def unmask(content)
|
def unmask(content)
|
||||||
|
|
|
@ -11,6 +11,13 @@ module WikiChunk
|
||||||
# another wiki page.
|
# another wiki page.
|
||||||
class WikiLink < Chunk::Abstract
|
class WikiLink < Chunk::Abstract
|
||||||
|
|
||||||
|
attr_reader :page_name, :link_text, :link_type
|
||||||
|
|
||||||
|
def initialize(*args)
|
||||||
|
super
|
||||||
|
@link_type = 'show'
|
||||||
|
end
|
||||||
|
|
||||||
def self.apply_to(content)
|
def self.apply_to(content)
|
||||||
content.gsub!( self.pattern ) do |matched_text|
|
content.gsub!( self.pattern ) do |matched_text|
|
||||||
chunk = self.new($~)
|
chunk = self.new($~)
|
||||||
|
@ -31,21 +38,20 @@ module WikiChunk
|
||||||
# By default, no escaped text
|
# By default, no escaped text
|
||||||
def escaped_text() nil end
|
def escaped_text() nil end
|
||||||
|
|
||||||
# Delimit the link text with markers to replace later unless
|
# Replace link with a mask, but if the word is escaped, then don't replace it
|
||||||
# the word is escaped. In that case, just return the link text
|
def mask(content) escaped_text || "#{pre_mask}#{link_text}#{post_mask}" end
|
||||||
def mask(content) escaped_text || pre_mask + link_text + post_mask end
|
|
||||||
|
|
||||||
def regexp() /#{pre_mask}(.*)?#{post_mask}/ end
|
def regexp() /#{pre_mask}(.*)#{post_mask}/ end
|
||||||
|
|
||||||
def revert(content) content.sub!(regexp, text) end
|
def revert(content) content.sub!(regexp, text) end
|
||||||
|
|
||||||
# Do not keep this chunk if it is escaped.
|
# Do not keep this chunk if it is escaped.
|
||||||
# Otherwise, pass the link procedure a page_name and link_text and
|
# Otherwise, pass the link procedure a page_name and link_text and
|
||||||
# get back a string of HTML to replace the mask with.
|
# get back a string of HTML to replace the mask with.
|
||||||
def unmask(content)
|
def unmask(content)
|
||||||
return nil if escaped_text
|
return nil if escaped_text
|
||||||
return self if content.sub!(regexp) do |match|
|
return self if content.sub!(regexp) do |match|
|
||||||
content.page_link(page_name, $1)
|
content.page_link(page_name, $1, link_type)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -64,8 +70,6 @@ module WikiChunk
|
||||||
WIKI_WORD
|
WIKI_WORD
|
||||||
end
|
end
|
||||||
|
|
||||||
attr_reader :page_name
|
|
||||||
|
|
||||||
def initialize(match_data)
|
def initialize(match_data)
|
||||||
super(match_data)
|
super(match_data)
|
||||||
@textile_link_suffix, @escape, @page_name = match_data[1..3]
|
@textile_link_suffix, @escape, @page_name = match_data[1..3]
|
||||||
|
@ -94,24 +98,16 @@ module WikiChunk
|
||||||
|
|
||||||
def self.pattern() WIKI_LINK end
|
def self.pattern() WIKI_LINK end
|
||||||
|
|
||||||
|
|
||||||
attr_reader :page_name, :link_text, :link_type
|
|
||||||
|
|
||||||
def initialize(match_data)
|
def initialize(match_data)
|
||||||
super(match_data)
|
super(match_data)
|
||||||
|
|
||||||
@textile_link_suffix, @page_name = match_data[1..2]
|
@textile_link_suffix, @page_name = match_data[1..2]
|
||||||
|
|
||||||
# defaults
|
|
||||||
@link_type = 'show'
|
|
||||||
@link_text = @page_name
|
@link_text = @page_name
|
||||||
|
|
||||||
separate_link_type
|
separate_link_type
|
||||||
separate_alias
|
separate_alias
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
# if link wihin the brackets has a form of [[filename:file]] or [[filename:pic]],
|
# if link wihin the brackets has a form of [[filename:file]] or [[filename:pic]],
|
||||||
# this means a link to a picture or a file
|
# this means a link to a picture or a file
|
||||||
def separate_link_type
|
def separate_link_type
|
||||||
|
@ -121,7 +117,7 @@ module WikiChunk
|
||||||
@link_type = link_type_match[2..3].compact[0]
|
@link_type = link_type_match[2..3].compact[0]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# link text may be different from page name. this will look like [[actual page|link text]]
|
# link text may be different from page name. this will look like [[actual page|link text]]
|
||||||
def separate_alias
|
def separate_alias
|
||||||
alias_match = ALIAS_SEPARATION.match(@page_name)
|
alias_match = ALIAS_SEPARATION.match(@page_name)
|
||||||
|
|
|
@ -48,18 +48,23 @@ class Web
|
||||||
page = pages[name]
|
page = pages[name]
|
||||||
text = text || WikiWords.separate(name)
|
text = text || WikiWords.separate(name)
|
||||||
link = CGI.escape(name)
|
link = CGI.escape(name)
|
||||||
|
link_type = options[:link_type] || :show
|
||||||
|
|
||||||
case options[:mode]
|
case options[:mode]
|
||||||
when :export
|
when :export
|
||||||
if page then "<a class=\"existingWikiWord\" href=\"#{link}.html\">#{text}</a>"
|
if page then "<a class=\"existingWikiWord\" href=\"#{link}.html\">#{text}</a>"
|
||||||
else "<span class=\"newWikiWord\">#{text}</span>" end
|
else "<span class=\"newWikiWord\">#{text}</span>" end
|
||||||
when :publish
|
when :publish
|
||||||
if page then "<a class=\"existingWikiWord\" href=\"../published/#{link}\">#{text}</a>"
|
if page then "<a class=\"existingWikiWord\" href=\"../published/#{link}\">#{text}</a>"
|
||||||
else "<span class=\"newWikiWord\">#{text}</span>" end
|
else "<span class=\"newWikiWord\">#{text}</span>" end
|
||||||
else
|
else
|
||||||
if page then "<a class=\"existingWikiWord\" href=\"../show/#{link}\">#{text}</a>"
|
if page
|
||||||
else "<span class=\"newWikiWord\">#{text}<a href=\"../show/#{link}\">?</a></span>" end
|
"<a class=\"existingWikiWord\" href=\"../#{link_type}/#{link}\">#{text}</a>"
|
||||||
|
else
|
||||||
|
"<span class=\"newWikiWord\">#{text}<a href=\"../#{link_type}/#{link}\">?</a></span>"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -39,9 +39,8 @@ require 'chunks/nowiki'
|
||||||
# UPDATED: 22nd May 2004
|
# UPDATED: 22nd May 2004
|
||||||
class WikiContent < String
|
class WikiContent < String
|
||||||
|
|
||||||
PRE_ENGINE_ACTIONS = [ NoWiki, Category, Include,
|
PRE_ENGINE_ACTIONS = [ NoWiki, Category, Include, URIChunk, LocalURIChunk, WikiChunk::Link,
|
||||||
URIChunk, LocalURIChunk,
|
WikiChunk::Word ]
|
||||||
WikiChunk::Link, WikiChunk::Word ]
|
|
||||||
POST_ENGINE_ACTIONS = [ Literal::Pre, Literal::Tags ]
|
POST_ENGINE_ACTIONS = [ Literal::Pre, Literal::Tags ]
|
||||||
DEFAULT_OPTS = {
|
DEFAULT_OPTS = {
|
||||||
:pre_engine_actions => PRE_ENGINE_ACTIONS,
|
:pre_engine_actions => PRE_ENGINE_ACTIONS,
|
||||||
|
@ -76,7 +75,8 @@ class WikiContent < String
|
||||||
end
|
end
|
||||||
|
|
||||||
# Call @web.page_link using current options.
|
# Call @web.page_link using current options.
|
||||||
def page_link(name, text)
|
def page_link(name, text, link_type)
|
||||||
|
@options[:link_type] = link_type || :show
|
||||||
@web.make_link(name, text, @options)
|
@web.make_link(name, text, @options)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -76,6 +76,6 @@ class WikiTest < Test::Unit::TestCase
|
||||||
assert_equal expected_link_text, chunk.link_text
|
assert_equal expected_link_text, chunk.link_text
|
||||||
assert_equal expected_link_type, chunk.link_type
|
assert_equal expected_link_type, chunk.link_type
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -210,6 +210,18 @@ class RevisionTest < Test::Unit::TestCase
|
||||||
"today</ins></p>", @page.revisions.last.display_diff
|
"today</ins></p>", @page.revisions.last.display_diff
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_link_to_file
|
||||||
|
assert_markup_parsed_as(
|
||||||
|
'<p><span class="newWikiWord">doc.pdf<a href="../file/doc.pdf">?</a></span></p>',
|
||||||
|
'[[doc.pdf:file]]')
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_link_to_pic
|
||||||
|
assert_markup_parsed_as(
|
||||||
|
'<p><span class="newWikiWord">Square<a href="../pic/square.jpg">?</a></span></p>',
|
||||||
|
'[[square.jpg|Square:pic]]')
|
||||||
|
end
|
||||||
|
|
||||||
# TODO Remove the leading underscores from this test when upgrading to RedCloth 3.0.1;
|
# 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)
|
# also add a test for the "Unhappy Face" problem (another interesting RedCloth bug)
|
||||||
def __test_list_with_tildas
|
def __test_list_with_tildas
|
||||||
|
|
Loading…
Reference in a new issue