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

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