Class: TextHelpers::ExternalLinks

Inherits:
Redcarpet::Render::HTML
  • Object
show all
Defined in:
lib/text_helpers/translation.rb

Constant Summary collapse

PROTOCOL_MATCHER =
/\Ahttp/.freeze

Instance Method Summary collapse

Instance Method Details



11
12
13
14
15
16
17
18
19
# File 'lib/text_helpers/translation.rb', line 11

def link(link, title, content)
  attributes = [
    ("href=\"#{link}\"" if link),
    ("title=\"#{title}\"" if title),
    ("target=\"_blank\" rel=\"noopener\"" if link.match?(PROTOCOL_MATCHER)),
  ]

  "<a #{attributes.compact.join(" ")}>#{content}</a>"
end