Skip to content

Commit 6d8e981

Browse files
committed
Add missing Jinja documentation
1 parent 1dd68fd commit 6d8e981

File tree

6 files changed

+40
-17
lines changed

6 files changed

+40
-17
lines changed

docs/community/related-projects.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,9 @@ Here are other projects that are related to django-pattern-library, and may be r
1616
- [Storybook](https://storybook.js.org/), and in particular [Storybook for Server](https://github.com/storybookjs/storybook/tree/master/app/server) – Storybook integration with server-rendered UI components.
1717
- [Pattern Lab](http://patternlab.io/) – PHP or Node pattern library, from which this project is heavily inspired.
1818
- [Astrum](http://astrum.nodividestudio.com/) – Similar to Pattern Lab, Node based.
19-
- [rikki-patterns](https://github.com/springload/rikki-patterns) – Experimental Django-friendly pattern library generator, for Jinja2 and Nunjucks templates
19+
- [rikki-patterns](https://github.com/springload/rikki-patterns) – Experimental Django-friendly pattern library generator, for Jinja and Nunjucks templates
2020
- [django-lookbook](https://github.com/rails-inspire-django/django-lookbook) - Empower your Django development with this pluggable app for creating a robust component library. Includes preview system, documentation engine, and parameter editor for building modular UI effortlessly.
2121

22-
2322
## Pattern libraries based on Django
2423

2524
Here are open-source projects that maintain pattern libraries for Django.

docs/getting-started.md

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ We support:
1919

2020
- Django 4.2, 5.0, 5.1
2121
- Python 3.9, 3.10, 3.11, 3.12
22-
- Django Templates only, no Jinja support
22+
- Django Templates and Jinja (experimental)
2323
- Modern “evergreen” desktop and mobile browsers
2424

2525
## Configuration
@@ -36,7 +36,7 @@ INSTALLED_APPS = [
3636
]
3737
```
3838

39-
Also add `pattern_library.loader_tags` to `OPTIONS["builtins"]` into the `TEMPLATES` setting:
39+
For Django Templates, add `pattern_library.loader_tags` to `OPTIONS["builtins"]` into the `TEMPLATES` setting:
4040

4141
```python hl_lines="13 14 15"
4242
TEMPLATES = [
@@ -59,6 +59,15 @@ TEMPLATES = [
5959
]
6060
```
6161

62+
Experimental: for Jinja support, call `override_jinja_tags` in the file that contains your Jinja environment:
63+
64+
```python
65+
from pattern_library.monkey_utils import override_jinja_tags
66+
67+
if apps.is_installed("pattern_library"):
68+
override_jinja_tags()
69+
```
70+
6271
To see the detailed error pages generated by Django when you have `DEBUG = True` in the pattern library, you'll need to make sure you have `X_FRAME_OPTIONS` set, or your browser will block the response:
6372

6473
```python

docs/guides/overriding-template-tags.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
# Overriding template tags
22

3-
The package overrides the following Django tags:
3+
The package overrides Django’s `extends` and `include` tags, implementing custom behaviour for these tags only when rendering in the pattern library. It falls back to Django's standard behaviour on all other cases. This makes it possible to define fake template contexts once and then have it reused everywhere a template partial is included.
44

5-
- `{% extends %}`
6-
- `{% include %}`
5+
---
76

8-
It's required to allow us to define fake template context and override other template tags in YAML files.
9-
This package uses custom behaviour for these tags only when rendering pattern library and falls back to Django's standard behaviour on all other cases.
10-
11-
The override process has two parts:
7+
We can also override other template tags in YAML files. The override process has two parts:
128

139
1. Override your template tag with a mock implementation
1410
2. Define fake result for your tag in a YAML file
1511

12+
!!! warning "No Jinja support"
13+
14+
Overriding arbitrary template tags or functions is currently unsupported for Jinja templates.
15+
1616
## Providing a default value for template tags
1717

1818
To provide a default for a template tag, you need to provide a keyword argument default_html when overriding your tag.

docs/index.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@ The [django-pattern-library](https://pypi.org/project/django-pattern-library/) p
99
- Create reusable patterns by creating Django templates files as usual.
1010
- All patterns automatically show up in the pattern library’s interface.
1111
- Define data as YAML files for the templates to render with the relevant Django context.
12-
- Override Django templates tags as needed to mock the template’s dependencies.
12+
- Override Django Templates tags as needed to mock the template’s dependencies.
1313
- Document your patterns with Markdown.
14+
- Experimental: support for Jinja templates.
1415

1516
Here is a screenshot of the pattern library in action:
1617

@@ -45,4 +46,3 @@ To learn more about how this package can be used, have a look at our talk:
4546
[Reusable UI components: A journey from React to Wagtail](https://www.youtube.com/watch?v=isrOufI7TKc)
4647

4748
[![Reusable UI components: A journey from React to Wagtail](images/pattern-library-talk-youtube.webp)](https://www.youtube.com/watch?v=isrOufI7TKc)
48-

docs/reference/api.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ context:
2424
- 2
2525
- 3
2626
# Mapping from tag names to tag overrides.
27+
# Currently unsupported for Jinja templates.
2728
tags:
2829
error_tag:
2930
include:
@@ -135,14 +136,24 @@ PATTERN_LIBRARY = {
135136

136137
### `override_tag`
137138

138-
This function tells the pattern library which Django tags to override, and optionally supports providing a default value. See [Overriding template tags](../guides/overriding-template-tags.md) for more information.
139+
This function tells the pattern library which Django Templates tags to override, and optionally supports providing a default value. See [Overriding template tags](../guides/overriding-template-tags.md) for more information.
139140

140141
```python
141142
from pattern_library.monkey_utils import override_tag
142143
143144
override_tag(register, 'a_tag_name', default_html="https://example.com/")
144145
```
145146

147+
### `override_jinja_tags`
148+
149+
🚧 Experimental. Optionally override `extends` and `include` in Jinja templates, so context for partials can be defined once and reused everywhere. See [Overriding template tags](../guides/overriding-template-tags.md). Call this in your Django settings file or at the top level of the file defining your Jinja environment.
150+
151+
```python
152+
from pattern_library.monkey_utils import override_jinja_tags
153+
154+
override_jinja_tags()
155+
```
156+
146157
## `register_context_modifier`
147158

148159
This decorator makes it possible to override or create additional context data with Django / Python code, rather than being limited to YAML. It has to be called from within a `pattern_contexts` module, which can be at the root of any Django app. See [Modifying template contexts with Python](../guides/defining-template-context.md#modifying-template-contexts-with-python) for more information.

docs/reference/known-issues.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ django-pattern-library has a few known limitations due to its design, which are
44

55
## Overriding filters is not supported
66

7-
See [#114](https://github.com/torchbox/django-pattern-library/issues/114). PRs welcome!
7+
See [#114](https://github.com/torchbox/django-pattern-library/issues/114) for Django Templates. PRs welcome!
88

99
## Can’t override context in a child template
1010

@@ -62,12 +62,16 @@ See [#138](https://github.com/torchbox/django-pattern-library/issues/138). For e
6262

6363
This can’t be mocked for all usage of `include_block`.
6464

65-
## Jinja2 support
65+
## Jinja2 overrides
6666

67-
Or lack thereof! If you’re interested in this, please share your thoughts with us on [#180](https://github.com/torchbox/django-pattern-library/discussions/180).
67+
There is experimental support, excluding overrides of arbitrary tags, functions, and filters. If you’re interested in this, please share your thoughts with us on [#180](https://github.com/torchbox/django-pattern-library/discussions/180).
6868

6969
## Past limitations
7070

71+
### Jinja2 support
72+
73+
🎉 This is now addressed as of v1.4.0, though with only experimental support, and no capability to override tags, functions, filters (see above).
74+
7175
### No way to specify objects that have attributes and support iteration
7276

7377
🎉 This is now addressed as of v0.5.0, with the [context modifiers in Python](../guides/defining-template-context.md#modifying-template-contexts-with-python) API. View our [pagination](../recipes/pagination.md) recipe.

0 commit comments

Comments
 (0)