Make Taggable.format_tags more readable.
This commit is contained in:
parent
24702b9f6a
commit
73c79bdc0d
1 changed files with 6 additions and 5 deletions
|
|
@ -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
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue