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
|
else
|
||||||
known_page = web.has_file?(name)
|
known_page = web.has_file?(name)
|
||||||
description = web.description(name)
|
description = web.description(name)
|
||||||
|
description = CGI.escapeHTML(CGI.unescapeHTML(description)) if description
|
||||||
end
|
end
|
||||||
if (text == name)
|
if (text == name)
|
||||||
text = description || text
|
text = description || text
|
||||||
|
@ -29,7 +30,7 @@ class AbstractUrlGenerator
|
||||||
when :show
|
when :show
|
||||||
page_link(mode, name, text, web.address, known_page)
|
page_link(mode, name, text, web.address, known_page)
|
||||||
when :file
|
when :file
|
||||||
file_link(mode, name, text, web.address, known_page)
|
file_link(mode, name, text, web.address, known_page, description)
|
||||||
when :pic
|
when :pic
|
||||||
pic_link(mode, name, text, web.address, known_page)
|
pic_link(mode, name, text, web.address, known_page)
|
||||||
else
|
else
|
||||||
|
@ -43,11 +44,11 @@ class UrlGenerator < AbstractUrlGenerator
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def file_link(mode, name, text, web_address, known_file)
|
def file_link(mode, name, text, web_address, known_file, description)
|
||||||
case mode
|
case mode
|
||||||
when :export
|
when :export
|
||||||
if known_file
|
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
|
else
|
||||||
%{<span class="newWikiWord">#{text}</span>}
|
%{<span class="newWikiWord">#{text}</span>}
|
||||||
end
|
end
|
||||||
|
@ -55,7 +56,7 @@ class UrlGenerator < AbstractUrlGenerator
|
||||||
if known_file
|
if known_file
|
||||||
href = @controller.url_for :controller => 'file', :web => web_address, :action => 'file',
|
href = @controller.url_for :controller => 'file', :web => web_address, :action => 'file',
|
||||||
:id => name
|
:id => name
|
||||||
%{<a class="existingWikiWord" title="#{text}" href="#{href}">#{text}</a>}
|
%{<a class="existingWikiWord" title="#{description}" href="#{href}">#{text}</a>}
|
||||||
else
|
else
|
||||||
%{<span class="newWikiWord">#{text}</span>}
|
%{<span class="newWikiWord">#{text}</span>}
|
||||||
end
|
end
|
||||||
|
@ -63,7 +64,7 @@ class UrlGenerator < AbstractUrlGenerator
|
||||||
href = @controller.url_for :controller => 'file', :web => web_address, :action => 'file',
|
href = @controller.url_for :controller => 'file', :web => web_address, :action => 'file',
|
||||||
:id => name
|
:id => name
|
||||||
if known_file
|
if known_file
|
||||||
%{<a class="existingWikiWord" title="#{text}" href="#{href}">#{text}</a>}
|
%{<a class="existingWikiWord" title="#{description}" href="#{href}">#{text}</a>}
|
||||||
else
|
else
|
||||||
%{<span class="newWikiWord">#{text}<a href="#{href}">?</a></span>}
|
%{<span class="newWikiWord">#{text}<a href="#{href}">?</a></span>}
|
||||||
end
|
end
|
||||||
|
|
|
@ -102,18 +102,18 @@ class StubUrlGenerator < AbstractUrlGenerator
|
||||||
super(:doesnt_need_controller)
|
super(:doesnt_need_controller)
|
||||||
end
|
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)
|
link = CGI.escape(name)
|
||||||
case mode
|
case mode
|
||||||
when :export
|
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
|
else %{<span class="newWikiWord">#{text}</span>} end
|
||||||
when :publish
|
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 %{<span class=\"newWikiWord\">#{text}</span>} end
|
||||||
else
|
else
|
||||||
if known_file
|
if known_file
|
||||||
%{<a class=\"existingWikiWord\" title="#{title}" href=\"../file/#{link}\">#{text}</a>}
|
%{<a class=\"existingWikiWord\" title="#{description}" href=\"../file/#{link}\">#{text}</a>}
|
||||||
else
|
else
|
||||||
%{<span class=\"newWikiWord\">#{text}<a href=\"../file/#{link}\">?</a></span>}
|
%{<span class=\"newWikiWord\">#{text}<a href=\"../file/#{link}\">?</a></span>}
|
||||||
end
|
end
|
||||||
|
|
|
@ -299,7 +299,7 @@ class PageRendererTest < Test::Unit::TestCase
|
||||||
'[[doc.pdf:file]]')
|
'[[doc.pdf:file]]')
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_link_to_pic
|
def test_link_to_pic_and_file
|
||||||
WikiFile.delete_all
|
WikiFile.delete_all
|
||||||
require 'fileutils'
|
require 'fileutils'
|
||||||
FileUtils.rm_rf("#{RAILS_ROOT}/public/wiki1/files/*")
|
FileUtils.rm_rf("#{RAILS_ROOT}/public/wiki1/files/*")
|
||||||
|
@ -310,6 +310,31 @@ class PageRendererTest < Test::Unit::TestCase
|
||||||
assert_markup_parsed_as(
|
assert_markup_parsed_as(
|
||||||
'<p><img alt="Square" src="../file/square.jpg" /></p>',
|
'<p><img alt="Square" src="../file/square.jpg" /></p>',
|
||||||
'[[square.jpg:pic]]')
|
'[[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
|
end
|
||||||
|
|
||||||
def test_link_to_non_existant_pic
|
def test_link_to_non_existant_pic
|
||||||
|
|
Loading…
Reference in a new issue