Commit e6090e71 authored by jakeburden's avatar jakeburden

Allow for the passing of options to external_link

parent 90dc19e9
# frozen_string_literal: true # frozen_string_literal: true
module ExternalLinkHelper module ExternalLinkHelper
def external_link(body, url) def external_link(body, url, options = {})
link_to url, target: '_blank', rel: 'noopener noreferrer' do link_to url, { target: '_blank', rel: 'noopener noreferrer' }.merge(options) do
"#{body} #{icon('external-link')}".html_safe "#{body} #{icon('external-link')}".html_safe
end end
end end
......
...@@ -9,4 +9,9 @@ describe ExternalLinkHelper do ...@@ -9,4 +9,9 @@ describe ExternalLinkHelper do
expect(external_link('https://gitlab.com', 'https://gitlab.com').to_s) expect(external_link('https://gitlab.com', 'https://gitlab.com').to_s)
.to eq('<a target="_blank" rel="noopener noreferrer" href="https://gitlab.com">https://gitlab.com <i aria-hidden="true" data-hidden="true" class="fa fa-external-link"></i></a>') .to eq('<a target="_blank" rel="noopener noreferrer" href="https://gitlab.com">https://gitlab.com <i aria-hidden="true" data-hidden="true" class="fa fa-external-link"></i></a>')
end end
it 'allows options when creating external link with icon' do
expect(external_link('https://gitlab.com', 'https://gitlab.com', { "data-foo": "bar", class: "externalLink" }).to_s)
.to eq('<a target="_blank" rel="noopener noreferrer" data-foo="bar" class="externalLink" href="https://gitlab.com">https://gitlab.com <i aria-hidden="true" data-hidden="true" class="fa fa-external-link"></i></a>')
end
end end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment