Skip to content

Commit

Permalink
Remove GOV.UK Frontend hard-coded paths
Browse files Browse the repository at this point in the history
Adds new Nunjucks locals from `govukFrontendPaths()` utility
  • Loading branch information
colinrotherham committed Sep 14, 2023
1 parent 15f8aff commit 9159606
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 4 deletions.
5 changes: 4 additions & 1 deletion lib/errorServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,10 @@ function runErrorServer (error) {
path.join(__dirname, 'nunjucks'),
...govukFrontendNunjucksPaths
])
res.end(nunjucksAppEnv.render('views/error-handling/server-error', getErrorModel(error)))
res.end(nunjucksAppEnv.render('views/error-handling/server-error', {
govukFrontendInternal, // Add GOV.UK Frontend paths to Nunjucks context
...getErrorModel(error)
}))
} catch (ignoreThisError) {
console.log(JSON.stringify({ ignoreThisError }, null, 2))
fileContentsParts.push('<h1 class="govuk-heading-l">There is an error</h1>')
Expand Down
2 changes: 1 addition & 1 deletion lib/nunjucks/govuk-prototype-kit/layouts/govuk-branded.njk
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{%- set assetPath = assetPath | default('/plugin-assets/govuk-frontend/govuk/assets') -%}
{%- set assetPath = assetPath | default('/plugin-assets/govuk-frontend' + govukFrontend.assetPath) -%}

{% extends "govuk/template.njk" %}

Expand Down
2 changes: 1 addition & 1 deletion lib/nunjucks/views/error-handling/server-error.njk
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{%- set assetPath = '/manage-prototype/dependencies/govuk-frontend/govuk/assets' -%}
{%- set assetPath = '/manage-prototype/dependencies/govuk-frontend' + govukFrontendInternal.assetPath -%}
{% extends "govuk-prototype-kit/layouts/govuk-branded.njk" %}

{% block pageTitle %}
Expand Down
2 changes: 1 addition & 1 deletion lib/nunjucks/views/manage-prototype/layout.njk
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{%- set assetPath = '/manage-prototype/dependencies/govuk-frontend/govuk/assets' -%}
{%- set assetPath = '/manage-prototype/dependencies/govuk-frontend' + govukFrontendInternal.assetPath -%}
{% extends "govuk-prototype-kit/layouts/govuk-branded.njk" %}

{% block pageTitle %}
Expand Down
8 changes: 8 additions & 0 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ if (isSecure) {
app.set('trust proxy', 1) // needed for secure cookies on heroku
}

// Find GOV.UK Frontend (via project, internal package fallback)
const govukFrontend = govukFrontendPaths([projectDir, packageDir])

// Find GOV.UK Frontend (via internal package, project fallback)
const govukFrontendInternal = govukFrontendPaths([packageDir, projectDir])

Expand All @@ -58,6 +61,11 @@ if (plugins.legacyGovukFrontendFixesNeeded()) {
app.locals.pluginConfig = plugins.getAppConfig({
scripts: utils.prototypeAppScripts
})

// Add GOV.UK Frontend paths to Nunjucks locals
app.locals.govukFrontend = govukFrontend
app.locals.govukFrontendInternal = govukFrontendInternal

// keep extensionConfig around for backwards compatibility
// TODO: remove in v14
app.locals.extensionConfig = app.locals.pluginConfig
Expand Down

0 comments on commit 9159606

Please sign in to comment.