GDS (GOV.UK) provide components in Nunjucks but in HMRC we tend to use Twirl.
Convert GDS's Nunjucks components into Twirl components
We approached this as an experiment, not expecting to produce production-ready maintainable code but looking for a quick answer to whether or not this was possible. One shortcut we took was to start with a fork of Nunjucks so we have access to all the inner workings - that means a lot of this project is not actually relevant to the work we've done.
It looks possible, it is likely to be particularly time consuming to build and maintain this transpiler.
- Clone the project
npm install
- Try it out with some of the built-in examples:
node transpiler.js components-to-transpile/backlink.njk
node transpiler.js components-to-transpile/hint.njk
node transpiler.js components-to-transpile/panel.njk
- Try it out with some other nunjucks templates:
Copy the contents of a file for example GOV.UK's Panel
Run pbpaste | node transpiler.js
and see the output or pbpaste | node transpiler.js > ../panel.scala.html