Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/cloudratha/djanjucks
A Django flavoured Template Engine running on Nunjucks. 🤷♂️
https://github.com/cloudratha/djanjucks
django nunjucks template
Last synced: 2 months ago
JSON representation
A Django flavoured Template Engine running on Nunjucks. 🤷♂️
- Host: GitHub
- URL: https://github.com/cloudratha/djanjucks
- Owner: cloudratha
- License: mit
- Created: 2019-06-13T18:03:27.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2023-01-04T04:32:10.000Z (about 2 years ago)
- Last Synced: 2024-10-11T19:18:01.676Z (3 months ago)
- Topics: django, nunjucks, template
- Language: JavaScript
- Homepage:
- Size: 836 KB
- Stars: 5
- Watchers: 0
- Forks: 3
- Open Issues: 13
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
## Under the hood
Djanjucks uses Nunjucks as a template engine but extends the compiler and parser to align to Django's templating format.
It extends the Nunjucks Environment with the tags and filters with feature comparitiy to Django.## Why does this exist?
I started looking for a library that could parse Django templates into static html with libraries like `Storybook`.
Nunjucks is inspired by Jinja, so it is a close match for Django's template syntax.This project started off as multiple nested regex replacements that attempted to transform django templates into Nunjucks templates.
This required a custom webpack loader to precompile templates. Eventually I relaised I could extend the base compiler and parser to work with Django natively.## What's not included
Djanjucks tries to implement all the default tags and filters that come built-in with Django. However some tags have been omitted because they don't make sense in a frontend context. These are `csrf_token`, `i18n`, `l10n`, `tz`, and `static`. Also the soon to be deprecated tags `ifequal` and `ifnotequal` are not included.
## Python support
Currently Djanjucks does not implement the `installJinjaCompat` Nunjucks extension. This could possibly be added in down the line with a custom implementation.
## Installation
```bash
npm install --save djanjucks
```Installation follows the Nunjucks API:
```js
import djanjucks from 'djanjucks';djanjucks.configure({ autoescape: true });
djanjucks.renderString('Hello {{ username }}', { username: 'James' });
```See more about methods, see [Nunjucks API Documentation](https://mozilla.github.io/nunjucks/api.html)
## Usage
For documentation on supported tags and filters, see [Django's Template Documentation](https://docs.djangoproject.com/en/2.2/ref/templates/builtins).