-
Notifications
You must be signed in to change notification settings - Fork 334
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
Add lib functions renderTemplate()
and renderPreview()
etc
#4329
Conversation
📋 StatsFile sizes
Modules
View stats and visualisations on the review app Action run for 699dccc |
5e4c831
to
130b1f5
Compare
130b1f5
to
4a1c0e8
Compare
4a1c0e8
to
aef20a1
Compare
aef20a1
to
f10e155
Compare
f10e155
to
f34d290
Compare
f34d290
to
11e07aa
Compare
11e07aa
to
629872d
Compare
629872d
to
326f090
Compare
326f090
to
c2cc1ae
Compare
This is preparation work for a new `renderTemplate()` function which will be compatible with the same options E.g. Nunjucks render `context` is universally `options.context` whether rendered by Nunjucks or called by a Puppeteer test
This makes `renderTemplate()` available to the Review app by adding it to `@govuk-frontend/lib` Like the `render()` test helper, the Cheerio version stays in `@govuk-frontend/helpers`
This will be used to bypass the Review app in future
Test helpers and lib functions are now consistent Library functions always return strings, but test helpers are available for Nunjucks (via Cheerio) and Google Chrome (via Puppeteer page) ``` import { render } from '@govuk-frontend/lib/components' import { render } from '@govuk-frontend/helpers/nunjucks' import { render } from '@govuk-frontend/helpers/puppeteer' ```
c2cc1ae
to
699dccc
Compare
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.
Looks good. I like the generic rendering to string from lib
then specialised in nunjucks
to get a cheerio object and in puppeteer
to run on the page. Only a little question, but it's not a blocker, just a confirmation that I understood that change correctly.
@@ -19,6 +19,9 @@ const frontendPath = packageTypeToPath('govuk-frontend', { | |||
|
|||
router.use('/assets', express.static(join(frontendPath, 'assets'))) | |||
router.use('/javascripts', express.static(frontendPath)) | |||
router.use('/stylesheets', express.static(join(paths.app, 'dist/stylesheets'))) | |||
router.use('/stylesheets', [ | |||
express.static(frontendPath), |
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.
question Just to confirm that I understand this change properly: this leads Express to also look in govuk-frontend
(however resolved earlier in the file) alongside looking at the built stylesheets from the review app. In turn, this enables it to find the /stylesheets/govuk-frontend.min.css
from the boilerplate markup, is that it?
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.
Yeah Express.js accepts an array of routes to try in order
Makes sure we can resolve CSS files from both locations:
/stylesheets/govuk-frontend.min.css
/stylesheets/app.min.css
We chatted on Slack yesterday that we could bypass the Review app and render HTML using:
This PR adds new lib functions
renderTemplate()
andrenderPreview()
to make it possible✅ Pre-built styles
govuk-frontend.min.css
✅ Pre-built script
govuk-frontend.min.js
✅ Lib functions to render components
❌ Lib functions to render templates and previews
Shared test helpers and library functions
This PR also aligns options between render functions and helpers, matching up their names too
@govuk-frontend/helpers
import test and dev dependencies (local use only)@govuk-frontend/lib
import production dependencies (deployed to Heroku)