fix whitespace, remove old no_follow code (nokogiri to the rescue)

This commit is contained in:
rick
2011-01-17 09:09:00 -08:00
parent ca2aaa543a
commit 11fcf0c784
+25 -42
View File
@@ -135,13 +135,11 @@ module Gollum
# final markup. # final markup.
# #
# data - The String data (with placeholders). # data - The String data (with placeholders).
# no_follow - Boolean that determines if rel="nofollow" is added to all
# <a> tags.
# #
# Returns the marked up String data. # Returns the marked up String data.
def process_tags(data, no_follow = false) def process_tags(data)
@tagmap.each do |id, tag| @tagmap.each do |id, tag|
data.gsub!(id, process_tag(tag, no_follow)) data.gsub!(id, process_tag(tag))
end end
data data
end end
@@ -150,17 +148,15 @@ module Gollum
# #
# tag - The String tag contents (the stuff inside the double # tag - The String tag contents (the stuff inside the double
# brackets). # brackets).
# no_follow - Boolean that determines if rel="nofollow" is added to all
# <a> tags.
# #
# Returns the String HTML version of the tag. # Returns the String HTML version of the tag.
def process_tag(tag, no_follow = false) def process_tag(tag)
if html = process_image_tag(tag) if html = process_image_tag(tag)
html html
elsif html = process_file_link_tag(tag, no_follow) elsif html = process_file_link_tag(tag)
html html
else else
process_page_link_tag(tag, no_follow) process_page_link_tag(tag)
end end
end end
@@ -255,12 +251,10 @@ module Gollum
# #
# tag - The String tag contents (the stuff inside the double # tag - The String tag contents (the stuff inside the double
# brackets). # brackets).
# no_follow - Boolean that determines if rel="nofollow" is added to all
# <a> tags.
# #
# Returns the String HTML if the tag is a valid file link tag or nil # Returns the String HTML if the tag is a valid file link tag or nil
# if it is not. # if it is not.
def process_file_link_tag(tag, no_follow = false) def process_file_link_tag(tag)
parts = tag.split('|') parts = tag.split('|')
name = parts[0].strip name = parts[0].strip
path = parts[1] && parts[1].strip path = parts[1] && parts[1].strip
@@ -272,53 +266,42 @@ module Gollum
nil nil
end end
tag = if name && path && file if name && path && file
%{<a href="#{::File.join @wiki.base_path, file.path}">#{name}</a>} %{<a href="#{::File.join @wiki.base_path, file.path}">#{name}</a>}
elsif name && path elsif name && path
%{<a href="#{path}">#{name}</a>} %{<a href="#{path}">#{name}</a>}
else else
nil nil
end end
if tag && no_follow
tag.sub! /^<a/, '<a ref="nofollow"'
end
tag
end end
# Attempt to process the tag as a page link tag. # Attempt to process the tag as a page link tag.
# #
# tag - The String tag contents (the stuff inside the double # tag - The String tag contents (the stuff inside the double
# brackets). # brackets).
# no_follow - Boolean that determines if rel="nofollow" is added to all
# <a> tags.
# #
# Returns the String HTML if the tag is a valid page link tag or nil # Returns the String HTML if the tag is a valid page link tag or nil
# if it is not. # if it is not.
def process_page_link_tag(tag, no_follow = false) def process_page_link_tag(tag)
parts = if @format == :mediawiki parts = tag.split('|')
tag.split('|').reverse parts.reverse! if @format == :mediawiki
else
tag.split('|')
end
name, page_name = *parts.compact.map(&:strip) name, page_name = *parts.compact.map(&:strip)
cname = @wiki.page_class.cname(page_name || name) cname = @wiki.page_class.cname(page_name || name)
tag = if name =~ %r{^https?://} && page_name.nil?
%{<a href="#{name}">#{name}</a>} if name =~ %r{^https?://} && page_name.nil?
else %{<a href="#{name}">#{name}</a>}
presence = "absent" else
link_name = cname presence = "absent"
page, extra = find_page_from_name(cname) link_name = cname
if page page, extra = find_page_from_name(cname)
link_name = @wiki.page_class.cname(page.name) if page
presence = "present" link_name = @wiki.page_class.cname(page.name)
end presence = "present"
link = ::File.join(@wiki.base_path, CGI.escape(link_name)) end
%{<a class="internal #{presence}" href="#{link}#{extra}">#{name}</a>} link = ::File.join(@wiki.base_path, CGI.escape(link_name))
end %{<a class="internal #{presence}" href="#{link}#{extra}">#{name}</a>}
if tag && no_follow
tag.sub! /^<a/, '<a rel="nofollow"'
end end
tag
end end
# Find the given file in the repo. # Find the given file in the repo.
@@ -393,7 +376,7 @@ module Gollum
formatted = begin formatted = begin
lang && Gollum::Albino.colorize(code, lang) lang && Gollum::Albino.colorize(code, lang)
rescue ::Albino::ShellArgumentError, ::Albino::Process::TimeoutExceeded, rescue ::Albino::ShellArgumentError, ::Albino::Process::TimeoutExceeded,
::Albino::Process::MaximumOutputExceeded ::Albino::Process::MaximumOutputExceeded
end end
formatted ||= "<pre><code>#{CGI.escapeHTML(code)}</code></pre>" formatted ||= "<pre><code>#{CGI.escapeHTML(code)}</code></pre>"