Small refactoring in web.rb (replaced three lines with one)

This commit is contained in:
Alexey Verkhovsky 2005-03-29 06:00:07 +00:00
parent dcfc6a48c4
commit 6367ef38c4

View file

@ -56,8 +56,7 @@ class Web
wiki.file_yard(self).has_file?(name)
end
def make_file_link(mode, name, text, base_url)
link = CGI.escape(name)
def make_file_link(mode, link, text, base_url)
case mode
when :export
if has_file?(name) then "<a class=\"existingWikiWord\" href=\"#{link}.html\">#{text}</a>"
@ -81,23 +80,23 @@ class Web
# It should not be used in menus, templates and such - instead, use link_to_page helper
def make_link(name, text = nil, options = {})
text = CGI.escapeHTML(text || WikiWords.separate(name))
link = CGI.escape(name)
mode = options[:mode] || :show
base_url = options[:base_url] || '..'
link_type = options[:link_type] || :show
case link_type.to_sym
when :show
make_page_link(mode, name, text, base_url)
make_page_link(mode, link, text, base_url)
when :file
make_file_link(mode, name, text, base_url)
make_file_link(mode, link, text, base_url)
when :pic
make_pic_link(mode, name, text, base_url)
make_pic_link(mode, link, text, base_url)
else
raise "Unknown link type: #{link_type}"
end
end
def make_page_link(mode, name, text, base_url)
link = CGI.escape(name)
def make_page_link(mode, link, text, base_url)
case mode.to_sym
when :export
if has_page?(name) then %{<a class="existingWikiWord" href="#{link}.html">#{text}</a>}
@ -114,8 +113,7 @@ class Web
end
end
def make_pic_link(mode, name, text, base_url)
link = CGI.escape(name)
def make_pic_link(mode, link, text, base_url)
case mode.to_sym
when :export
if has_file?(name) then %{<img alt="#{text}" src="#{link}" />}