Small refactoring in web.rb (replaced three lines with one)
This commit is contained in:
parent
dcfc6a48c4
commit
6367ef38c4
|
@ -56,8 +56,7 @@ class Web
|
||||||
wiki.file_yard(self).has_file?(name)
|
wiki.file_yard(self).has_file?(name)
|
||||||
end
|
end
|
||||||
|
|
||||||
def make_file_link(mode, name, text, base_url)
|
def make_file_link(mode, link, text, base_url)
|
||||||
link = CGI.escape(name)
|
|
||||||
case mode
|
case mode
|
||||||
when :export
|
when :export
|
||||||
if has_file?(name) then "<a class=\"existingWikiWord\" href=\"#{link}.html\">#{text}</a>"
|
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
|
# It should not be used in menus, templates and such - instead, use link_to_page helper
|
||||||
def make_link(name, text = nil, options = {})
|
def make_link(name, text = nil, options = {})
|
||||||
text = CGI.escapeHTML(text || WikiWords.separate(name))
|
text = CGI.escapeHTML(text || WikiWords.separate(name))
|
||||||
|
link = CGI.escape(name)
|
||||||
mode = options[:mode] || :show
|
mode = options[:mode] || :show
|
||||||
base_url = options[:base_url] || '..'
|
base_url = options[:base_url] || '..'
|
||||||
link_type = options[:link_type] || :show
|
link_type = options[:link_type] || :show
|
||||||
case link_type.to_sym
|
case link_type.to_sym
|
||||||
when :show
|
when :show
|
||||||
make_page_link(mode, name, text, base_url)
|
make_page_link(mode, link, text, base_url)
|
||||||
when :file
|
when :file
|
||||||
make_file_link(mode, name, text, base_url)
|
make_file_link(mode, link, text, base_url)
|
||||||
when :pic
|
when :pic
|
||||||
make_pic_link(mode, name, text, base_url)
|
make_pic_link(mode, link, text, base_url)
|
||||||
else
|
else
|
||||||
raise "Unknown link type: #{link_type}"
|
raise "Unknown link type: #{link_type}"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def make_page_link(mode, name, text, base_url)
|
def make_page_link(mode, link, text, base_url)
|
||||||
link = CGI.escape(name)
|
|
||||||
case mode.to_sym
|
case mode.to_sym
|
||||||
when :export
|
when :export
|
||||||
if has_page?(name) then %{<a class="existingWikiWord" href="#{link}.html">#{text}</a>}
|
if has_page?(name) then %{<a class="existingWikiWord" href="#{link}.html">#{text}</a>}
|
||||||
|
@ -114,8 +113,7 @@ class Web
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def make_pic_link(mode, name, text, base_url)
|
def make_pic_link(mode, link, text, base_url)
|
||||||
link = CGI.escape(name)
|
|
||||||
case mode.to_sym
|
case mode.to_sym
|
||||||
when :export
|
when :export
|
||||||
if has_file?(name) then %{<img alt="#{text}" src="#{link}" />}
|
if has_file?(name) then %{<img alt="#{text}" src="#{link}" />}
|
||||||
|
|
Loading…
Reference in a new issue