Commit 90dc19e9 authored by jakeburden's avatar jakeburden

Create and use external_link helper

Creates a helper method that takes body text and a url.

The output is a external link with icon.

It contains the noopenner noreferrer attributes for security.

Usage: external_link(domain.title, domain.url)

Add rspec test for ExternalLinkHelper

Add changelog for MR 32130
parent 5c25a757
# frozen_string_literal: true
module ExternalLinkHelper
def external_link(body, url)
link_to url, target: '_blank', rel: 'noopener noreferrer' do
"#{body} #{icon('external-link')}".html_safe
end
end
end
......@@ -8,14 +8,10 @@
= _("Your pages are served under:")
%p
= link_to @project.pages_url, target: '_blank', rel: 'noopener noreferrer' do
= @project.pages_url
= icon('external-link')
= external_link(@project.pages_url, @project.pages_url)
- @project.pages_domains.each do |domain|
%p
= link_to domain.url, target: '_blank', rel: 'noopener noreferrer' do
= domain.url
= icon('external-link')
= external_link(domain.url, domain.url)
.card-footer.alert-primary
= _("It may take up to 30 minutes before the site is available after the first deployment.")
......@@ -12,9 +12,7 @@
.domain-status.ci-status-icon.has-tooltip{ class: "ci-status-icon-#{status}", title: tooltip }
= sprite_icon("status_#{status}", size: 16 )
.domain-name
= link_to domain.url, target: '_blank', rel: 'noopener noreferrer' do
= domain.url
= icon('external-link')
= external_link(domain.url, domain.url)
- if domain.subject
%div
%span.badge.badge-gray Certificate: #{domain.subject}
......
......@@ -21,9 +21,7 @@
%td
= _("Domain")
%td
= link_to @domain.url, target: :_blank, rel: 'noopener noreferrer' do
= @domain.url
= icon('external-link')
= external_link(@domain.url, @domain.url)
%tr
%td
= _("DNS")
......
---
title: Makes custom Pages domain open as external link in new tab
merge_request: 32130
author: jakeburden
type: fixed
# frozen_string_literal: true
require 'spec_helper'
describe ExternalLinkHelper do
include IconsHelper
it 'returns external link with icon' do
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>')
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