We were inconsistent on this one. I consider it particularly useful when a method starts with a `return` statement. In other cases, we probably shouldn't have a guard rule in the middle of a method in any case, but that's a different refactoring.
20 lines
533 B
Ruby
20 lines
533 B
Ruby
module TextWithLinksHelper
|
|
def sanitize_and_auto_link(text)
|
|
return unless text
|
|
|
|
sanitized = sanitize(text, tags: [], attributes: [])
|
|
auto_link_already_sanitized_html(sanitized)
|
|
end
|
|
|
|
def auto_link_already_sanitized_html(html)
|
|
return if html.nil?
|
|
raise "Could not add links because the content is not safe" unless html.html_safe?
|
|
|
|
raw Rinku.auto_link(html, :all, 'target="_blank" rel="nofollow"')
|
|
end
|
|
|
|
def simple_format_no_tags_no_sanitize(html)
|
|
simple_format(html, {}, sanitize: false)
|
|
end
|
|
end
|