Class: GovukPublishingComponents::Presenters::AbsoluteLinksHelper

Inherits:
Object
  • Object
show all
Defined in:
lib/govuk_publishing_components/presenters/absolute_links_helper.rb

Instance Method Summary collapse

Instance Method Details

#make_url_absolute(href) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/govuk_publishing_components/presenters/absolute_links_helper.rb', line 4

def make_url_absolute(href)
  # If the URL is already absolute do nothing
  unless href.start_with?("/")
    return href
  end

  host = ENV["VIRTUAL_HOST"] || Plek.new.website_root

  unless host.start_with?("http://", "https://", "//")
    host = "//#{host}" # '//' preserves the current protocol, we shouldn't force https as that would break dev environments
  end

  "#{host}#{href}"
end