-
Notifications
You must be signed in to change notification settings - Fork 18
Feature/add hods theme #412
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
45c16ac
2d5cff1
b21a407
bb2c9bb
9b4cf68
5fe19fd
5e52df3
84deb6c
869dfe7
f56df51
0afc6c1
558a6ed
f0e991e
fd72418
fb21510
be0f61f
46bffc4
6e2eb3b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| /* eslint-disable no-console */ | ||
| 'use strict'; | ||
|
|
||
| const fs = require('fs'); | ||
| const chalk = require('chalk'); | ||
| const spawn = require('../../lib/spawn'); | ||
| const mkdir = require('../../lib/mkdir'); | ||
|
|
||
| module.exports = config => { | ||
| if (!config.fonts) { | ||
| return Promise.resolve(); | ||
| } | ||
|
|
||
| return new Promise((resolve, reject) => { | ||
| fs.stat(config.fonts.src, err => err ? reject(err) : resolve()); | ||
| }) | ||
| .then(() => mkdir(config.fonts.out)) | ||
| .then(() => spawn('cp', ['-r', config.fonts.src, config.fonts.out])) | ||
| .catch(e => { | ||
| if (e.code !== 'ENOENT') { | ||
| throw e; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm trying to understand this, if you catch an error that doesn't have a specific path/ file directory, you'll throw an error? Would it be better to provide a helpful error message? |
||
| } else { | ||
| console.log(`${chalk.yellow('warning')}: no fonts directory found at ${config.fonts.src}`); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nice use of chalk 👍 |
||
| } | ||
| }); | ||
| }; | ||
| module.exports.task = 'copy fonts'; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| 'use strict'; | ||
| /* eslint max-len: 0 */ | ||
| module.exports = { | ||
| afterHeader: '{{$afterHeader}}{{/afterHeader}}', | ||
| appTitle: '{{$journeyHeader}}{{/journeyHeader}}', | ||
| assetPath: '{{govukAssetPath}}', | ||
| bodyClasses: '{{$bodyClasses}}{{/bodyClasses}}', | ||
| bodyEnd: '{{$bodyEnd}}{{/bodyEnd}}', | ||
| bodyStart: '{{$bodyStart}}{{/bodyStart}}', | ||
| content: '{{$main}}{{/main}}', | ||
| cookieMessage: '{{$cookieMessage}}{{/cookieMessage}}', | ||
| crownCopyrightMessage: '{{$crownCopyrightMessage}}© Crown copyright{{/crownCopyrightMessage}}', | ||
| footerSupportLinks: '{{$footerSupportLinks}}{{/footerSupportLinks}}', | ||
| footerTop: '{{$footerTop}}{{/footerTop}}', | ||
| globalHeaderText: '{{$globalHeaderText}}GOV.UK{{/globalHeaderText}}', | ||
| head: '{{$head}}{{/head}}', | ||
| headerClass: '{{$headerClass}}{{/headerClass}}', | ||
| homepageUrl: '{{$homepageUrl}}https://www.gov.uk{{/homepageUrl}}', | ||
| htmlLang: '{{htmlLang}}', | ||
| insideHeader: '{{$insideHeader}}{{/insideHeader}}', | ||
| licenceMessage: '{{$licenceMessage}}All content is available under the <a href="https://www.nationalarchives.gov.uk/doc/open-government-licence/version/3/" id="open-government-licence" class="govuk-footer__link" target="_blank" rel="license">Open Government Licence v3.0</a>, except where otherwise stated{{/licenceMessage}}', | ||
| logoLinkTitle: '{{$logoLinkTitle}}Go to the GOV.UK homepage{{/logoLinkTitle}}', | ||
| pageTitle: '{{$pageTitle}}{{/pageTitle}}', | ||
| propositionHeader: '{{$propositionHeader}}{{/propositionHeader}}', | ||
| }; |
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| 'use strict'; | ||
|
|
||
| const Hogan = require('hogan.js'); | ||
| const fs = require('fs'); | ||
| const path = require('path'); | ||
| const govukConfig = require('./config'); | ||
|
|
||
| function addNonceValueAttributeToInlineScripts(compiledTemplateString) { | ||
| const scriptNonceValue = '{{#nonce}}nonce="{{nonce}}"{{/nonce}}'; | ||
| return compiledTemplateString.replace(/(<script)((?![^>]+src).*?)>/g, | ||
| `$1$2 ${scriptNonceValue}>`); | ||
| } | ||
|
|
||
| module.exports = () => { | ||
| const template = require.resolve('./hods_template.html'); | ||
|
|
||
| const govukTemplate = fs.readFileSync(template, { encoding: 'utf-8' }); | ||
| const compiledTemplate = Hogan.compile(govukTemplate).render(govukConfig); | ||
| const parsedTemplate = addNonceValueAttributeToInlineScripts(compiledTemplate); | ||
| const output = path.resolve(__dirname, '../hods_template_generated.html'); | ||
|
|
||
| fs.writeFileSync(output, parsedTemplate, { encoding: 'utf-8' }); | ||
| }; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| /* eslint-disable */ | ||
| 'use strict'; | ||
|
|
||
| const path = require('path'); | ||
| const express = require('express'); | ||
| const template = require('../index'); | ||
|
|
||
| const app = express(); | ||
|
|
||
| app.engine('html', require('hogan-express')); | ||
| app.set('view engine', 'html'); | ||
| app.set('views', path.resolve(__dirname, 'views')); | ||
|
|
||
| app.use(template()); | ||
| app.get('*', (req, res) => { | ||
| res.render('index'); | ||
| }); | ||
|
|
||
| app.listen(3000); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| { | ||
| "name": "hmpo-govuk-template-example", | ||
| "description": "Example app for hmpo-govuk-template module", | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why does it say hmpo? |
||
| "version": "0.0.0", | ||
| "scripts": { | ||
| "start": "node index.js" | ||
| }, | ||
| "main": "index.js", | ||
| "dependencies": { | ||
| "express": "^4.11.2", | ||
| "hof-govuk-template": "^2.1.0", | ||
| "hogan-express": "^0.5.2" | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| {{< hods-template}} | ||
|
|
||
| {{$pageTitle}}HMPO Template Example{{/pageTitle}} | ||
|
|
||
| {{$head}} | ||
| <style> | ||
| .main { | ||
| width: 960px; | ||
| margin: 10px auto; | ||
| } | ||
| </style> | ||
| {{/head}} | ||
|
|
||
| {{$main}} | ||
| <div class="main"> | ||
| <h1>It works!!</h1> | ||
| </div> | ||
| {{/main}} | ||
|
|
||
| {{/ hods-template}} | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. new line |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| 'use strict'; | ||
|
|
||
| const path = require('path'); | ||
| const servestatic = require('serve-static'); | ||
| const Router = require('express').Router; | ||
| const buildTemplateLayout = require('./build'); | ||
|
|
||
| const basedir = path.dirname(require.resolve('govuk-frontend/package.json')); | ||
|
|
||
| const setup = (opts, router) => { | ||
| buildTemplateLayout(); | ||
| const options = opts || {}; | ||
| options.path = options.path || '/assets'; | ||
|
|
||
| router.use(options.path, servestatic(path.join(basedir, './govuk/assets'), options)); | ||
| router.use((req, res, next) => { | ||
| res.locals.govukAssetPath = req.baseUrl + options.path + '/'; | ||
| res.locals.partials = res.locals.partials || {}; | ||
| res.locals.partials['govuk-template'] = path.resolve(__dirname, './hods_template_generated'); | ||
| next(); | ||
| }); | ||
|
|
||
| return router; | ||
| }; | ||
|
|
||
| module.exports = (options, app) => { | ||
| const router = app || new Router(); | ||
| return setup(options, router); | ||
| }; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,145 @@ | ||
| /* eslint-disable max-len, no-var, vars-on-top, no-undef */ | ||
| 'use strict'; | ||
|
|
||
| // TODO: update package.json(s) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what do you need to update in package.json(s) would it be best to do as this PR? |
||
|
|
||
| function hideFallbackContent(containerId) { | ||
| var container = document.getElementById(containerId); | ||
| if (container === null) return; | ||
| var fallbackContent = container.getElementsByClassName('js-disabled'); | ||
| for (var i = 0; i < fallbackContent.length; i++) { | ||
| fallbackContent[i].style.display = 'none'; | ||
| } | ||
| } | ||
|
|
||
| function showInteractiveContent(containerId) { | ||
| var container = document.getElementById(containerId); | ||
| if (container === null) return; | ||
| var interactiveContent = container.getElementsByClassName('js-enabled'); | ||
| for (var i = 0; i < interactiveContent.length; i++) { | ||
| interactiveContent[i].style.display = 'block'; | ||
| } | ||
| } | ||
|
|
||
| function setCookiePreferences(preferences) { | ||
| GOVUK.cookie('cookie_preferences', JSON.stringify(preferences), { days: 30 }); | ||
|
|
||
| if (!preferences.usage) { | ||
| GOVUK.cookie('_ga', null); | ||
| GOVUK.cookie('_gat', null); | ||
| GOVUK.cookie('_gid', null); | ||
| } | ||
| } | ||
|
|
||
| function showCookieBannerSubmitted() { | ||
| document.getElementById('cookie-banner-info').style.display = 'none'; | ||
| document.getElementById('cookie-banner-actions').style.display = 'none'; | ||
| var cookieBannerSubmitted = document.getElementById('cookie-banner-submitted'); | ||
| cookieBannerSubmitted.style.display = 'block'; | ||
| cookieBannerSubmitted.focus(); | ||
| } | ||
|
|
||
| function initialiseBannerButtons() { | ||
| document.getElementById('accept-cookies-button').addEventListener('click', function () { | ||
| setCookiePreferences({essential: true, usage: true}); | ||
| showCookieBannerSubmitted(); | ||
| sessionStorage.setItem('reloading', 'true'); | ||
| window.location = document.URL; | ||
| }); | ||
|
|
||
| document.getElementById('reject-cookies-button').addEventListener('click', function () { | ||
| setCookiePreferences({essential: true, usage: false}); | ||
| showCookieBannerSubmitted(); | ||
| }); | ||
|
|
||
| document.getElementById('hide-cookie-banner').addEventListener('click', function () { | ||
| document.getElementById('cookie-banner').style.display = 'none'; | ||
| }); | ||
| } | ||
|
|
||
| function initialiseCookieBanner() { | ||
| var preferences = GOVUK.cookie('cookie_preferences'); | ||
|
|
||
| if (preferences !== null) { | ||
| return; | ||
| } | ||
|
|
||
| // the default cookie message container from hof-govuk-template | ||
| var bannerContainer = document.getElementById('global-cookie-message'); | ||
|
|
||
| // the cookie banner that will replace the container's default content if using google analytics | ||
| var cookieBanner = document.getElementById('cookie-banner'); | ||
|
|
||
| if (bannerContainer !== null && cookieBanner !== null) { | ||
| hideFallbackContent('global-cookie-message'); | ||
| showInteractiveContent('global-cookie-message'); | ||
| bannerContainer.style.display = 'block'; | ||
| initialiseBannerButtons(); | ||
| } | ||
| } | ||
|
|
||
| function handleSaveSettings(e) { | ||
| e.preventDefault(); | ||
| setCookiePreferences({ essential: true, usage: document.getElementById('radio-1').checked }); | ||
|
|
||
| var cookieNotification = document.getElementById('cookie-notification'); | ||
| var cookieBanner = document.getElementById('cookie-banner'); | ||
|
|
||
| if (cookieBanner !== null) { | ||
| cookieBanner.style.display = 'none'; | ||
| } | ||
|
|
||
| if (cookieNotification !== null) { | ||
| cookieNotification.style.display = 'block'; | ||
| cookieNotification.focus(); | ||
| } | ||
| } | ||
|
|
||
| function initialiseFormControls() { | ||
| var preferences = JSON.parse(GOVUK.cookie('cookie_preferences')); | ||
| var usage; | ||
|
|
||
| if (preferences !== null && preferences.usage !== undefined && typeof preferences.usage === 'boolean') { | ||
| usage = preferences.usage; | ||
| } else { | ||
| usage = false; | ||
| } | ||
|
|
||
| document.getElementById('radio-1').checked = usage; | ||
| document.getElementById('radio-2').checked = !usage; | ||
| document.getElementById('save-cookie-settings').addEventListener('click', handleSaveSettings); | ||
| } | ||
|
|
||
| function initialiseCookiePage() { | ||
| var shouldDisplayCookieControls = document.getElementById('cookie-settings') !== null; | ||
|
|
||
| if (shouldDisplayCookieControls) { | ||
| hideFallbackContent('cookie-settings'); | ||
| showInteractiveContent('cookie-settings'); | ||
| initialiseFormControls(); | ||
| } | ||
| } | ||
|
|
||
| function onLoad() { | ||
| window.onload = function () { | ||
| var reloading = sessionStorage.getItem('reloading'); | ||
| if (reloading) { | ||
| sessionStorage.removeItem('reloading'); | ||
|
|
||
| var bannerContainer = document.getElementById('global-cookie-message'); | ||
| var cookieBanner = document.getElementById('cookie-banner'); | ||
|
|
||
| if (bannerContainer !== null && cookieBanner !== null) { | ||
| bannerContainer.style.display = 'block'; | ||
| } | ||
| initialiseBannerButtons(); | ||
| showCookieBannerSubmitted(); | ||
| } | ||
| }; | ||
| } | ||
|
|
||
| module.exports = { | ||
| initialiseCookieBanner: initialiseCookieBanner, | ||
| initialiseCookiePage: initialiseCookiePage, | ||
| onLoad: onLoad | ||
| }; | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
new line? you can add this in your editor to prevent this happening in the future