Make Taggable.format_tags more readable.

This commit is contained in:
Pistos 2011-11-01 00:41:56 -04:00
parent 24702b9f6a
commit 73c79bdc0d

View file

@ -41,12 +41,13 @@ module Diaspora
def self.format_tags(text, opts={})
return text if opts[:plain_text]
text = ERB::Util.h(text) unless opts[:no_escape]
regex = /(^|\s|>)#(#{VALID_TAG_BODY})/
form_message = text.to_str.gsub(regex) do |matched_string|
"#{$~[1]}<a href=\"/tags/#{$~[2]}\" class=\"tag\">##{$~[2]}</a>"
end
form_message.html_safe
text.to_str.gsub(regex) { |matched_string|
%{#{$1}<a href="/tags/#{$2}" class="tag">##{$2}</a>}
}.html_safe
end
end
end