Skip to content

Commit

Permalink
Move example templates into lib folder (and drop NHS website template…
Browse files Browse the repository at this point in the history
…s) (#409)

This moves the example templates in `/lib/` and also drops the NHS.UK
website templates (which remain on https://prototype-kit.service-manual.nhs.uk/page-templates ).

This is partly as they’re no longer documentation but purely example
page templates, and partly to try and make future updating easier by
moving towards having a single folder (currently called `lib`) which
users could manually update by copying and pasting (or possibly using a
script or in future an npm package).

The new folder with the templates is `lib/example-templates`.

Because the NHS.UK website templates have been dropped, this also means
that the `nhs.scss` can be deleted, as can the images used in the NHS
website templates.

Have also updated and simplified the `app.js` file.
  • Loading branch information
frankieroberto authored Dec 10, 2024
1 parent 823ecf0 commit 200609a
Show file tree
Hide file tree
Showing 57 changed files with 111 additions and 8,140 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
- Changed all references from 'NHS.UK prototype kit' to 'NHS prototype kit'
- Update default index page ([PR 423](https://github.com/nhsuk/nhsuk-prototype-kit/pull/423))
- Import task list component ([PR 437](https://github.com/nhsuk/nhsuk-prototype-kit/pull/437))
- The example page templates have moved from the `docs` folder to `lib/example-templates` - ([PR 409](https://github.com/nhsuk/nhsuk-prototype-kit/pull/409))


## 5.1.0 - 12 November 2024

Expand Down
80 changes: 27 additions & 53 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,17 @@ const automaticRouting = require('./middleware/auto-routing');
const config = require('./app/config');
const locals = require('./app/locals');
const routes = require('./app/routes');
const documentationRoutes = require('./docs/documentation_routes');
const utils = require('./lib/utils');

const prototypeAdminRoutes = require('./middleware/prototype-admin-routes');
const exampleTemplatesRoutes = require('./lib/example_templates_routes');

// Set configuration variables
const port = parseInt(process.env.PORT, 10) || config.port;
const useDocumentation = process.env.SHOW_DOCS || config.useDocumentation;
const onlyDocumentation = process.env.DOCS_ONLY;

// Initialise applications
const app = express();
const documentationApp = express();
const exampleTemplatesApp = express();

// Set up configuration variables
const useAutoStoreData = process.env.USE_AUTO_STORE_DATA || config.useAutoStoreData;
Expand All @@ -51,7 +49,7 @@ app.use(cookieParser());
// Nunjucks configuration for application
const appViews = [
path.join(__dirname, 'app/views/'),
path.join(__dirname, 'docs/views/'),
path.join(__dirname, 'lib/example-templates/'),
path.join(__dirname, 'lib/prototype-admin/'),
path.join(__dirname, 'node_modules/nhsuk-frontend/packages/components'),
path.join(__dirname, 'node_modules/nhsuk-frontend/packages/macros'),
Expand Down Expand Up @@ -83,7 +81,7 @@ const sessionOptions = {
app.use(authentication);

// Support session data in cookie or memory
if (useCookieSessionStore === 'true' && !onlyDocumentation) {
if (useCookieSessionStore === 'true') {
app.use(sessionInCookie(Object.assign(sessionOptions, {
cookieName: sessionName,
proxy: true,
Expand Down Expand Up @@ -148,21 +146,13 @@ app.use(locals(config));

// View engine
app.set('view engine', 'html');
documentationApp.set('view engine', 'html');
exampleTemplatesApp.set('view engine', 'html');

// Middleware to serve static assets
app.use(express.static(path.join(__dirname, 'public')));
app.use('/nhsuk-frontend', express.static(path.join(__dirname, 'node_modules/nhsuk-frontend/packages')));
app.use('/nhsuk-frontend', express.static(path.join(__dirname, 'node_modules/nhsuk-frontend/dist')));

// Check if the app is documentation only
if (onlyDocumentation === 'true') {
app.get('/', (req, res) => {
// Redirect to the documentation pages if it is
res.redirect('/docs');
});
}

// Use custom application routes
app.use('/', routes);

Expand All @@ -171,47 +161,31 @@ app.get(/^([^.]+)$/, (req, res, next) => {
automaticRouting.matchRoutes(req, res, next);
});

// Check if the app is using documentation
if (useDocumentation || onlyDocumentation === 'true') {
// Documentation routes
app.use('/docs', documentationApp);

// Nunjucks configuration for documentation
const docViews = [
path.join(__dirname, 'docs/views/'),
path.join(__dirname, 'node_modules/nhsuk-frontend/packages/components'),
path.join(__dirname, 'node_modules/nhsuk-frontend/packages/macros'),
];

nunjucksAppEnv = nunjucks.configure(docViews, {
autoescape: true,
express: documentationApp,
});
nunjucksAppEnv.addGlobal('version', packageInfo.version);

// Add Nunjucks filters
utils.addNunjucksFilters(nunjucksAppEnv);

// Automatically store all data users enter
if (useAutoStoreData === 'true') {
documentationApp.use(utils.autoStoreData);
utils.addCheckedFunction(nunjucksAppEnv);
}
// Example template routes
app.use('/example-templates', exampleTemplatesApp);

// Nunjucks configuration for example templates
const exampleTemplateViews = [
path.join(__dirname, 'lib/example-templates/'),
path.join(__dirname, 'node_modules/nhsuk-frontend/packages/components'),
path.join(__dirname, 'node_modules/nhsuk-frontend/packages/macros'),
];

nunjucksAppEnv = nunjucks.configure(exampleTemplateViews, {
autoescape: true,
express: exampleTemplatesApp,
});
nunjucksAppEnv.addGlobal('version', packageInfo.version);

// Support for parsing data in POSTs
documentationApp.use(bodyParser.json());
documentationApp.use(bodyParser.urlencoded({
extended: true,
}));
// Add Nunjucks filters
utils.addNunjucksFilters(nunjucksAppEnv);

// Custom documentation routes
documentationApp.use('/', documentationRoutes);
exampleTemplatesApp.use('/', exampleTemplatesRoutes);

// Automatically route documentation pages
documentationApp.get(/^([^.]+)$/, (req, res, next) => {
automaticRouting.matchRoutes(req, res, next);
});
}
// Automatically route example template pages
exampleTemplatesApp.get(/^([^.]+)$/, (req, res, next) => {
automaticRouting.matchRoutes(req, res, next);
});

app.use('/prototype-admin', prototypeAdminRoutes);

Expand Down
3 changes: 0 additions & 3 deletions app/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,4 @@ module.exports = {
// Enable cookie-based session store (persists on restart)
// Please note 4KB cookie limit per domain, cookies too large will silently be ignored
useCookieSessionStore: 'false',

// Enable or disable built-in docs and examples.
useDocumentation: true,
};
3 changes: 1 addition & 2 deletions app/views/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,8 @@ <h2 class="nhsuk-heading-l">
</ul>

<p>
There is a selection of <a href="/docs/page-templates">example page templates</a> in <strong>/docs/views/</strong>. To use these, copy and paste them into <strong>/app/views/</strong>.
There is a selection of <a href="/example-templates">example page templates</a> in <strong>/lib/example-templates/</strong>. To use these, copy and paste them into <strong>/app/views/</strong>.
</p>

<!-- End of content -->

</div>
Expand Down
6 changes: 3 additions & 3 deletions app/views/layout.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
- add custom CSS and JavaScript
-->

<!-- Extends the layout from /docs/views/template.html -->
<!-- Extends the layout from /lib/example-templates/template.html -->
{% extends "template.html" %}

<!-- Add your custom CSS or Sass in /app/assets/sass/main.scss -->
Expand Down Expand Up @@ -41,8 +41,8 @@
"label": "Home"
},
{
"URL": "/docs/page-templates",
"label": "Example page templates"
"URL": "/example-templates",
"label": "Page templates"
}
]
})}}
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading

0 comments on commit 200609a

Please sign in to comment.