From 1d45259eb0d440e1a1ffa88558796b78453286f3 Mon Sep 17 00:00:00 2001 From: Laurence de Bruxelles Date: Wed, 17 Aug 2022 12:37:38 +0100 Subject: [PATCH 1/3] Make GOV.UK Frontend assets paths work with http prefix Co-authored-by: Oliver Byford --- lib/assets/stylesheets/_govuk_tech_docs.scss | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/lib/assets/stylesheets/_govuk_tech_docs.scss b/lib/assets/stylesheets/_govuk_tech_docs.scss index 3080ec35..2b444236 100644 --- a/lib/assets/stylesheets/_govuk_tech_docs.scss +++ b/lib/assets/stylesheets/_govuk_tech_docs.scss @@ -1,4 +1,20 @@ -$govuk-assets-path: "/assets/govuk/assets/" !default; +// Set $govuk-assets-path so that $govuk-images-path and $govuk-fonts-path +// (used below, but set in govuk/base) are correct. +$govuk-assets-path: "/assets/govuk/assets/"; + +// Use Sprockets' asset url helpers to add the http prefix if present. +// GOV.UK Frontend provides hooks for us to define the url lookup functions, +// see https://frontend.design-system.service.gov.uk/sass-api-reference/ +@function tech-docs-image-url-function($filename) { + @return image-url($govuk-images-path + $filename); +} + +@function tech-docs-font-url-function($filename) { + @return font-url($govuk-fonts-path + $filename); +} + +$govuk-font-url-function: "tech-docs-font-url-function"; +$govuk-image-url-function: "tech-docs-image-url-function"; // Include only the bits of GOV.UK Frontend we need $govuk-new-link-styles: true; From efca683b6ff330acf19523f873d5da2151b56a9b Mon Sep 17 00:00:00 2001 From: Laurence de Bruxelles Date: Wed, 17 Aug 2022 15:08:15 +0100 Subject: [PATCH 2/3] Add deprecation warning for govuk_assets_path Setting govuk_assets_path should no longer be necessary, and to keep the code simple it will no longer have any effect. This commit lets users know about this change in case it causes them some surprise. --- lib/govuk_tech_docs.rb | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/lib/govuk_tech_docs.rb b/lib/govuk_tech_docs.rb index 4cacd978..8c2f2752 100644 --- a/lib/govuk_tech_docs.rb +++ b/lib/govuk_tech_docs.rb @@ -24,12 +24,24 @@ require "govuk_tech_docs/api_reference/api_reference_extension" module GovukTechDocs + class GovukTechDocsExtension < Middleman::Extension + def after_configuration + if app.config[:govuk_assets_path] + warn "Warning: setting govuk_assets_path in config.rb is no longer necessary, and will have no effect." + end + end + end + + ::Middleman::Extensions.register(:govuk_tech_docs, GovukTechDocsExtension) + # Configure the tech docs template # # @param options [Hash] # @option options [Hash] livereload Options to pass to the `livereload` # extension. Hash with symbols as keys. def self.configure(context, options = {}) + context.activate :govuk_tech_docs + context.activate :sprockets context.sprockets.append_path File.join(__dir__, "../node_modules/govuk-frontend/") From 2420f66483aaf824a9b2533106df10055ccd8cda Mon Sep 17 00:00:00 2001 From: Laurence de Bruxelles Date: Tue, 25 Jan 2022 09:14:36 +0000 Subject: [PATCH 3/3] Update changelog --- CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index c1e97740..2da2189e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,12 @@ ## Unreleased +### Fixes + +You no longer need to change the Sass variable govuk-assets-path when using a http prefix; the tech docs gem will add the prefix for you. + +- [#292: Make GOV.UK Frontend assets path work with http prefix](https://github.com/alphagov/tech-docs-gem/pull/292) + ## 3.2.1 ### Fixes