Sync with trunk

This commit is contained in:
Jason Blevins 2007-10-09 20:02:02 -04:00
commit f785655a59
5 changed files with 24 additions and 12 deletions

View file

@ -47,6 +47,11 @@ class Web < ActiveRecord::Base
WikiFile.find_by_file_name(file_name) != nil
end
def description(file_name)
file = WikiFile.find_by_file_name(file_name)
file.description if file
end
def markup
read_attribute('markup').to_sym
end

View file

@ -9,7 +9,7 @@
{ 'multipart' => true , 'accept-charset' => 'utf-8' }) do %>
<div class="inputFieldWithPrompt">
<%= hidden_field 'file', 'file_name' %>
<label for="file_content"><b>Content of <%= h @file_name %> to upload</b> (required):</label>
<label for="file_content"><b>Content of <%= h @file_name %> to upload</b>:</label>
<br />
<input type="file" id="file_content" name="file[content]" size="40" />
<br />
@ -18,7 +18,7 @@
<%= link_to :back %> and edit the wiki page that refers to the file.
</div>
<div class="inputFieldWithPrompt">
<label for="file_description"><b>Description</b> (optional):</label>
<label for="file_description"><b>Description</b>:</label>
<br/>
<%= text_field "file", "description", "size" => 40 %>
</div>

View file

@ -9,7 +9,6 @@ class AbstractUrlGenerator
# on the render mode in options and whether the page (file) exists
# in the web.
def make_link(name, web, text = nil, options = {})
text = CGI.escapeHTML(text || WikiWords.separate(name))
mode = (options[:mode] || :show).to_sym
link_type = (options[:link_type] || :show).to_sym
@ -17,7 +16,14 @@ class AbstractUrlGenerator
known_page = web.has_page?(name)
else
known_page = web.has_file?(name)
description = web.description(name)
end
if (text == name)
text = description || text
else
text = text || description
end
text = CGI.escapeHTML(CGI.unescapeHTML(text || WikiWords.separate(name)))
case link_type
when :show
@ -41,7 +47,7 @@ class UrlGenerator < AbstractUrlGenerator
case mode
when :export
if known_file
%{<a class="existingWikiWord" href="#{CGI.escape(name)}.html">#{text}</a>}
%{<a class="existingWikiWord" title="#{text}" href="#{CGI.escape(name)}.html">#{text}</a>}
else
%{<span class="newWikiWord">#{text}</span>}
end
@ -49,7 +55,7 @@ class UrlGenerator < AbstractUrlGenerator
if known_file
href = @controller.url_for :controller => 'file', :web => web_address, :action => 'file',
:id => name
%{<a class="existingWikiWord" href="#{href}">#{text}</a>}
%{<a class="existingWikiWord" title="#{text}" href="#{href}">#{text}</a>}
else
%{<span class="newWikiWord">#{text}</span>}
end
@ -57,7 +63,7 @@ class UrlGenerator < AbstractUrlGenerator
href = @controller.url_for :controller => 'file', :web => web_address, :action => 'file',
:id => name
if known_file
%{<a class="existingWikiWord" href="#{href}">#{text}</a>}
%{<a class="existingWikiWord" title="#{text}" href="#{href}">#{text}</a>}
else
%{<span class="newWikiWord">#{text}<a href="#{href}">?</a></span>}
end

View file

@ -106,14 +106,14 @@ class StubUrlGenerator < AbstractUrlGenerator
link = CGI.escape(name)
case mode
when :export
if known_file then %{<a class="existingWikiWord" href="#{link}.html">#{text}</a>}
if known_file then %{<a class="existingWikiWord" title="#{title}" href="#{link}.html">#{text}</a>}
else %{<span class="newWikiWord">#{text}</span>} end
when :publish
if known_file then %{<a class="existingWikiWord" href="../published/#{link}">#{text}</a>}
if known_file then %{<a class="existingWikiWord" title="#{title}" href="../published/#{link}">#{text}</a>}
else %{<span class=\"newWikiWord\">#{text}</span>} end
else
if known_file
%{<a class=\"existingWikiWord\" href=\"../file/#{link}\">#{text}</a>}
%{<a class=\"existingWikiWord\" title="#{title}" href=\"../file/#{link}\">#{text}</a>}
else
%{<span class=\"newWikiWord\">#{text}<a href=\"../file/#{link}\">?</a></span>}
end
@ -144,6 +144,7 @@ class StubUrlGenerator < AbstractUrlGenerator
def pic_link(mode, name, text, web_name, known_pic)
link = CGI.escape(name)
text = CGI.escapeHTML(CGI.unescapeHTML(text || :description))
case mode.to_sym
when :export
if known_pic then %{<img alt="#{text}" src="#{link}" />}

View file

@ -305,10 +305,10 @@ class PageRendererTest < Test::Unit::TestCase
FileUtils.rm_rf("#{RAILS_ROOT}/public/wiki1/files/*")
@web.wiki_files.create(:file_name => 'square.jpg', :description => 'Square', :content => 'never mind')
assert_markup_parsed_as(
'<p><img alt="Square" src="../file/square.jpg" /></p>',
'[[square.jpg|Square:pic]]')
'<p><img alt="Blue Square" src="../file/square.jpg" /></p>',
'[[square.jpg|Blue Square:pic]]')
assert_markup_parsed_as(
'<p><img alt="square.jpg" src="../file/square.jpg" /></p>',
'<p><img alt="Square" src="../file/square.jpg" /></p>',
'[[square.jpg:pic]]')
end