question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Supply layout template for other languages (Rails, Python...)

See original GitHub issue

When implementing the Design System in a Rails app, I am able to include the assets (CSS, JS, fonts, images) easily enough, but the only layout file supplied is template.njk so I have to manually create views/layouts/application.slim myself, and then it will degrade over time and need to be recreated when the system is updated.

It would be ace to have a slim or perhaps just erb version of the template for Rails apps.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:7 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
andymantellcommented, Sep 5, 2018

Hi @leonk,

The script I’ve pasted is fully working so in terms of viability I think it’s a goer. I’m happy that the templates are working correctly, barring any edge case bugs.

I did look meta-template briefly but the readme file suggested it was quite early days so I didn’t pursue it. I proceeded on the assumption that Jinja and Nunjucks were similar enough that a few string replacements would do the trick (true => True, quoting object/dict keys etc). The reality turned out to be a little more painful than I realised, but what I’ve done still mostly amounts to relatively simple string manipulation. The regular expressions got a bit gnarly, but conceptually the transformations weren’t complicated. A lot of the differences (particularly the more annoying ones) were the result of the behaviours of the underlying language. And one that was probably either a bug in Jinja or a bug in Nunjucks, because the GOV.UK Nunjucks implementation just did not work whatever I did (The bit where each component macro simply includes an include, and expects the params to still be there)

Given that Twig is inspired by Jinja (And actually written by the same guy) you might well get away with a similar process. Basically I kept adding lines to my script until Python stopped throwing errors.

Give it a go 😃

1reaction
hannalaaksocommented, Aug 24, 2018

This decision record is also useful context here as it details what was done in alpha and some of the challenges we’ve identified: https://github.com/alphagov/govuk-design-system-architecture/blob/master/decision-records/003-templating-languages.md

Read more comments on GitHub >

github_iconTop Results From Across the Web

Django switching, for a block of code, switch the language so ...
What do I put in to switch django translations/gettext to a specific language code so that the _() will use that language code?...
Read more >
Rails Internationalization (I18n) API - Ruby on Rails Guides
The process of “internationalization” usually means to abstract all strings and other locale specific bits (such as date or currency formats) out of...
Read more >
An Introduction to ERB Templating - Field Notes
Rails uses an improved version, called Erubis. The supplied documentation for ERB provides a good introduction: ri ERB. Writing Templates. ERB ...
Read more >
Kotlin DSL templates with Python (or any other) Server
Further, the description of page content becomes more concise than with conventional templates. More Languages? Or Less? It could be seen that ...
Read more >
Liquid Template Language | Twilio
Learn to use the Liquid Template Language to render dynamic content in ... all whitespace from the beginning of a string; map -...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found