File Upload Links
I like this a little better.
This commit is contained in:
parent
fbdf4c5dfe
commit
5dd75d4cb0
|
@ -17,6 +17,7 @@ class AbstractUrlGenerator
|
|||
else
|
||||
known_page = web.has_file?(name)
|
||||
description = web.description(name)
|
||||
description = CGI.escapeHTML(CGI.unescapeHTML(description)) if description
|
||||
end
|
||||
if (text == name)
|
||||
text = description || text
|
||||
|
@ -29,7 +30,7 @@ class AbstractUrlGenerator
|
|||
when :show
|
||||
page_link(mode, name, text, web.address, known_page)
|
||||
when :file
|
||||
file_link(mode, name, text, web.address, known_page)
|
||||
file_link(mode, name, text, web.address, known_page, description)
|
||||
when :pic
|
||||
pic_link(mode, name, text, web.address, known_page)
|
||||
else
|
||||
|
@ -43,11 +44,11 @@ class UrlGenerator < AbstractUrlGenerator
|
|||
|
||||
private
|
||||
|
||||
def file_link(mode, name, text, web_address, known_file)
|
||||
def file_link(mode, name, text, web_address, known_file, description)
|
||||
case mode
|
||||
when :export
|
||||
if known_file
|
||||
%{<a class="existingWikiWord" title="#{text}" href="#{CGI.escape(name)}.html">#{text}</a>}
|
||||
%{<a class="existingWikiWord" title="#{description}" href="#{CGI.escape(name)}.html">#{text}</a>}
|
||||
else
|
||||
%{<span class="newWikiWord">#{text}</span>}
|
||||
end
|
||||
|
@ -55,7 +56,7 @@ class UrlGenerator < AbstractUrlGenerator
|
|||
if known_file
|
||||
href = @controller.url_for :controller => 'file', :web => web_address, :action => 'file',
|
||||
:id => name
|
||||
%{<a class="existingWikiWord" title="#{text}" href="#{href}">#{text}</a>}
|
||||
%{<a class="existingWikiWord" title="#{description}" href="#{href}">#{text}</a>}
|
||||
else
|
||||
%{<span class="newWikiWord">#{text}</span>}
|
||||
end
|
||||
|
@ -63,7 +64,7 @@ class UrlGenerator < AbstractUrlGenerator
|
|||
href = @controller.url_for :controller => 'file', :web => web_address, :action => 'file',
|
||||
:id => name
|
||||
if known_file
|
||||
%{<a class="existingWikiWord" title="#{text}" href="#{href}">#{text}</a>}
|
||||
%{<a class="existingWikiWord" title="#{description}" href="#{href}">#{text}</a>}
|
||||
else
|
||||
%{<span class="newWikiWord">#{text}<a href="#{href}">?</a></span>}
|
||||
end
|
||||
|
|
|
@ -102,18 +102,18 @@ class StubUrlGenerator < AbstractUrlGenerator
|
|||
super(:doesnt_need_controller)
|
||||
end
|
||||
|
||||
def file_link(mode, name, text, web_name, known_file)
|
||||
def file_link(mode, name, text, web_name, known_file, description)
|
||||
link = CGI.escape(name)
|
||||
case mode
|
||||
when :export
|
||||
if known_file then %{<a class="existingWikiWord" title="#{title}" href="#{link}.html">#{text}</a>}
|
||||
if known_file then %{<a class="existingWikiWord" title="#{description}" href="#{link}.html">#{text}</a>}
|
||||
else %{<span class="newWikiWord">#{text}</span>} end
|
||||
when :publish
|
||||
if known_file then %{<a class="existingWikiWord" title="#{title}" href="../published/#{link}">#{text}</a>}
|
||||
if known_file then %{<a class="existingWikiWord" title="#{description}" href="../published/#{link}">#{text}</a>}
|
||||
else %{<span class=\"newWikiWord\">#{text}</span>} end
|
||||
else
|
||||
if known_file
|
||||
%{<a class=\"existingWikiWord\" title="#{title}" href=\"../file/#{link}\">#{text}</a>}
|
||||
%{<a class=\"existingWikiWord\" title="#{description}" href=\"../file/#{link}\">#{text}</a>}
|
||||
else
|
||||
%{<span class=\"newWikiWord\">#{text}<a href=\"../file/#{link}\">?</a></span>}
|
||||
end
|
||||
|
|
|
@ -299,7 +299,7 @@ class PageRendererTest < Test::Unit::TestCase
|
|||
'[[doc.pdf:file]]')
|
||||
end
|
||||
|
||||
def test_link_to_pic
|
||||
def test_link_to_pic_and_file
|
||||
WikiFile.delete_all
|
||||
require 'fileutils'
|
||||
FileUtils.rm_rf("#{RAILS_ROOT}/public/wiki1/files/*")
|
||||
|
@ -310,6 +310,31 @@ class PageRendererTest < Test::Unit::TestCase
|
|||
assert_markup_parsed_as(
|
||||
'<p><img alt="Square" src="../file/square.jpg" /></p>',
|
||||
'[[square.jpg:pic]]')
|
||||
assert_markup_parsed_as(
|
||||
'<p><a class="existingWikiWord" title="Square" href="../file/square.jpg">Blue Square</a></p>',
|
||||
'[[square.jpg|Blue Square:file]]')
|
||||
assert_markup_parsed_as(
|
||||
'<p><a class="existingWikiWord" title="Square" href="../file/square.jpg">Square</a></p>',
|
||||
'[[square.jpg:file]]')
|
||||
end
|
||||
|
||||
def test_link_to_pic_and_file_null_desc
|
||||
WikiFile.delete_all
|
||||
require 'fileutils'
|
||||
FileUtils.rm_rf("#{RAILS_ROOT}/public/wiki1/files/*")
|
||||
@web.wiki_files.create(:file_name => 'square.jpg', :description => '', :content => 'never mind')
|
||||
assert_markup_parsed_as(
|
||||
'<p><img alt="Blue Square" src="../file/square.jpg" /></p>',
|
||||
'[[square.jpg|Blue Square:pic]]')
|
||||
assert_markup_parsed_as(
|
||||
'<p><img alt="" src="../file/square.jpg" /></p>',
|
||||
'[[square.jpg:pic]]')
|
||||
assert_markup_parsed_as(
|
||||
'<p><a class="existingWikiWord" title="" href="../file/square.jpg">Blue Square</a></p>',
|
||||
'[[square.jpg|Blue Square:file]]')
|
||||
assert_markup_parsed_as(
|
||||
'<p><a class="existingWikiWord" title="" href="../file/square.jpg"></a></p>',
|
||||
'[[square.jpg:file]]')
|
||||
end
|
||||
|
||||
def test_link_to_non_existant_pic
|
||||
|
|
Loading…
Reference in a new issue