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
This commit is contained in:
jakeburden 2019-08-30 18:16:39 -04:00
parent 5c25a757dc
commit 90dc19e9f0
6 changed files with 30 additions and 12 deletions

View file

@ -0,0 +1,9 @@
# 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

View file

@ -8,14 +8,10 @@
= _("Your pages are served under:") = _("Your pages are served under:")
%p %p
= link_to @project.pages_url, target: '_blank', rel: 'noopener noreferrer' do = external_link(@project.pages_url, @project.pages_url)
= @project.pages_url
= icon('external-link')
- @project.pages_domains.each do |domain| - @project.pages_domains.each do |domain|
%p %p
= link_to domain.url, target: '_blank', rel: 'noopener noreferrer' do = external_link(domain.url, domain.url)
= domain.url
= icon('external-link')
.card-footer.alert-primary .card-footer.alert-primary
= _("It may take up to 30 minutes before the site is available after the first deployment.") = _("It may take up to 30 minutes before the site is available after the first deployment.")

View file

@ -12,9 +12,7 @@
.domain-status.ci-status-icon.has-tooltip{ class: "ci-status-icon-#{status}", title: tooltip } .domain-status.ci-status-icon.has-tooltip{ class: "ci-status-icon-#{status}", title: tooltip }
= sprite_icon("status_#{status}", size: 16 ) = sprite_icon("status_#{status}", size: 16 )
.domain-name .domain-name
= link_to domain.url, target: '_blank', rel: 'noopener noreferrer' do = external_link(domain.url, domain.url)
= domain.url
= icon('external-link')
- if domain.subject - if domain.subject
%div %div
%span.badge.badge-gray Certificate: #{domain.subject} %span.badge.badge-gray Certificate: #{domain.subject}

View file

@ -21,9 +21,7 @@
%td %td
= _("Domain") = _("Domain")
%td %td
= link_to @domain.url, target: :_blank, rel: 'noopener noreferrer' do = external_link(@domain.url, @domain.url)
= @domain.url
= icon('external-link')
%tr %tr
%td %td
= _("DNS") = _("DNS")

View file

@ -0,0 +1,5 @@
---
title: Makes custom Pages domain open as external link in new tab
merge_request: 32130
author: jakeburden
type: fixed

View file

@ -0,0 +1,12 @@
# 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