Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
8d4aa61
add django-lookbook (#250)
michael-yin Dec 11, 2024
e41537b
Update usage-tips.md, note md extension for docs (#248)
bmihelac Dec 11, 2024
688568f
Release v1.3.0
thibaudcolas Dec 11, 2024
56a5848
Test with latest Python
thibaudcolas Apr 2, 2025
49612d6
Remove unneeded tests against Django main
thibaudcolas Apr 2, 2025
e2bee8a
Add Django 5.2rc1 to testing matrix
thibaudcolas Apr 2, 2025
556f47a
Try a different way to allow pre-releases in tox
thibaudcolas Apr 2, 2025
041a207
Add emoji favicon to avoid favicon.ico requests from the browser
thibaudcolas Apr 2, 2025
08d5654
Declare support for Django 5.2
thibaudcolas Apr 2, 2025
fd196fc
Prepare v1.4.0 for release
thibaudcolas Apr 2, 2025
c72a0f4
Remove Django <6.0 upper bound
thibaudcolas Apr 8, 2025
ce29fb8
Regenerate Poetry lockfile
thibaudcolas Apr 8, 2025
8a6c585
Update authors and maintainers
thibaudcolas Apr 8, 2025
6d9f653
Release v1.4.0
thibaudcolas Apr 8, 2025
a573237
Fix include pattern for Poetry v2+
thibaudcolas Apr 8, 2025
f8c685c
Release v1.4.1
thibaudcolas Apr 8, 2025
7becd4c
First pass at renderers
gone Jun 13, 2022
4465259
Moving from loading at the global level to loading at the template level
luord Jun 30, 2022
9bb3270
Got pattern library working
luord Jul 1, 2022
ad1a1ef
Fixed test_utils
luord Jul 1, 2022
a1f9fad
Fixed commands
luord Jul 5, 2022
c262579
move everything into lib
edcohen08 Jul 13, 2023
36493bc
more documentation
edcohen08 Jul 13, 2023
365e34e
no noqa
edcohen08 Jul 13, 2023
a9c9d30
reorg calling override, dont dupe
edcohen08 Jul 24, 2023
e369f8b
document
edcohen08 Jul 24, 2023
35b7634
Fix error accessing pattern template name
maribedran Dec 15, 2023
c5c01a7
Wrap rendered pattern HTML with mark_safe to render correctly on temp…
maribedran Dec 15, 2023
b91d101
fix: linting
CuriousLearner Feb 26, 2024
5b09a37
Run isort
CuriousLearner Feb 26, 2024
1573841
Add missing Jinja documentation
thibaudcolas Apr 8, 2025
7cbd288
Add basic Jinja tests
thibaudcolas Apr 8, 2025
c62587e
TODO-ify the missing Jinja tags / functions override support
thibaudcolas Apr 8, 2025
b43422d
Fix linting issues
thibaudcolas Apr 8, 2025
4e8679a
Upgrade to Node 23
thibaudcolas Apr 8, 2025
3b0f180
Upgrade all front-end dependencies
thibaudcolas Apr 8, 2025
3dd0b96
Release notes for Jinja support
thibaudcolas Apr 8, 2025
8d40b7e
Simplify Sass code reuse
thibaudcolas Apr 8, 2025
730fce3
Migrate to Sass use module system
thibaudcolas Apr 8, 2025
a741350
Update docs and CHANGELOG
thibaudcolas Apr 8, 2025
48c6082
Add missing 3.13 classifier
thibaudcolas Apr 8, 2025
16e05f8
Force regenerate Poetry lockfile
thibaudcolas Apr 8, 2025
8fb96a0
Upgrade dependencies with security vulnerabilities
thibaudcolas Apr 8, 2025
6c01a9e
Upgrade Poetry
thibaudcolas Apr 8, 2025
c9e9cf9
Release v1.5.0
thibaudcolas Apr 8, 2025
347e67d
Release v1.5.0
thibaudcolas Apr 8, 2025
a59cb3e
Remove unneeded Django RC specifier
thibaudcolas Apr 8, 2025
0182512
Mention yanked release in the CHANGELOG
thibaudcolas Apr 8, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 13 additions & 11 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: pipx install "poetry>=1.1.12,<2"
- run: pipx install "poetry>=2.1.2,<3"
- uses: actions/setup-python@v5
with:
python-version: "3.12"
cache: 'poetry'
python-version: "3.13"
cache: "poetry"
- run: pip install tox
- run: tox -e lint,py312-dj51
- run: tox -e lint,py313-dj51
test_compatibility:
needs: test
runs-on: ubuntu-latest
Expand All @@ -29,14 +29,16 @@ jobs:
- python: "3.9"
toxenv: py39-dj42
- python: "3.10"
toxenv: py310-dj42,py310-dj50,py311-dj51,py310-djmain
toxenv: py310-dj42,py310-dj51,py310-dj52
- python: "3.11"
toxenv: py311-dj42,py311-dj50,py311-dj51,py311-djmain
toxenv: py311-dj42,py311-dj51,py311-dj52
- python: "3.12"
toxenv: py312-dj42,py312-djmain
toxenv: py312-dj42,py312-dj52
- python: "3.13"
toxenv: py313-dj42,py313-dj52,py312-djmain
steps:
- uses: actions/checkout@v4
- run: pipx install "poetry>=1.1.12,<2"
- run: pipx install "poetry>=2.1.2,<3"
- uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python }}
Expand All @@ -52,7 +54,7 @@ jobs:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version-file: '.nvmrc'
node-version-file: ".nvmrc"
- id: node-cache
uses: actions/cache@v3
with:
Expand All @@ -62,11 +64,11 @@ jobs:
- if: steps.node-cache.outputs.cache-hit != 'true'
run: npm ci --no-audit
- run: npm run build
- run: pipx install "poetry>=1.1.12,<2"
- run: pipx install "poetry>=2.1.2,<3"
- uses: actions/setup-python@v5
with:
python-version-file: pyproject.toml
cache: 'poetry'
cache: "poetry"
- run: poetry install
- run: poetry run django-admin runserver --settings=tests.settings.production --pythonpath=. &
# Docs website build.
Expand Down
2 changes: 1 addition & 1 deletion .gitpod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ tasks:
# initialise and install the python part of the app by installing poetry
# and the python dependencies
- init: |
pip install "poetry>=1.1.12,<2"
pip install "poetry>=2.1.2,<3"
poetry install
gp sync-done python
# Start the server for testing
Expand Down
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
16
23
55 changes: 55 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,60 @@
# Changelog

## [Unreleased]

## [1.5.0](https://github.com/torchbox/django-pattern-library/releases/tag/v1.5.0) - 2025-04-08

### Added

- Add experimental Jinja support ([#180](https://github.com/torchbox/django-pattern-library/discussions/180), [#247](https://github.com/torchbox/django-pattern-library/pull/247), [#254](https://github.com/torchbox/django-pattern-library/pull/254)). Thank you to [@gone](https://github.com/gone), [@luord](https://github.com/luord), [@edcohen08](https://github.com/edcohen08), [@maribedran](https://github.com/maribedran), [@CuriousLearner](https://github.com/CuriousLearner)!

### Maintenance

- Update front-end tooling dependencies to latest versions

### Documentation

- Update Complementary packages list with recent options ([django-bird](https://github.com/joshuadavidthomas/django-bird), [dj-angles](https://github.com/adamghill/dj-angles), [django-cotton](https://github.com/wrabit/django-cotton))

## [1.4.1](https://github.com/torchbox/django-pattern-library/releases/tag/v1.4.1) - 2025-04-08

### Fixed

- Include static files in wheel build of the package

## [1.4.0](https://github.com/torchbox/django-pattern-library/releases/tag/v1.4.0) - 2025-04-08

Yanked from PyPI as its wheel was missing the pattern library’s static files.

### Added

- Add support for Django 5.2 ([#253](https://github.com/torchbox/django-pattern-library/issues/253))
- Add emoji favicon to avoid favicon.ico requests from the browser

### Removed

- Remove Django `<6.0` dependency upper bound, allowing installs of arbitrary future Django versions

## [1.3.0](https://github.com/torchbox/django-pattern-library/releases/tag/v1.3.0) - 2024-12-11

### Added

- Add support for Django 5.1 ([#251](https://github.com/torchbox/django-pattern-library/pull/251))

### Removed

- Drop support for Python 3.8 ([#251](https://github.com/torchbox/django-pattern-library/pull/251))
- Drop support for Django 4.1 ([#242](https://github.com/torchbox/django-pattern-library/pull/242))

### Documentation

- Note requirement for `.md` extension for pattern documentation files ([#248](https://github.com/torchbox/django-pattern-library/pull/248))
- Mention complementary package django-viewcomponent, and django-lookbook as an alternative. ([#250](https://github.com/torchbox/django-pattern-library/pull/250))

### Maintenance

- Test with Python 3.12 ([#242](https://github.com/torchbox/django-pattern-library/pull/242))

## [1.2.0](https://github.com/torchbox/django-pattern-library/releases/tag/v1.2.0) - 2024-01-16

### Added
Expand Down
3 changes: 1 addition & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

This document contains information for anyone wishing to contribute to the project.


## Installation

The repo includes a simple test application that can be run to develop the pattern library itself. Give it a try by [opening django-pattern-library in Gitpod](https://gitpod.io/#https://github.com/torchbox/django-pattern-library), or follow the instructions below for a local setup.
Expand Down Expand Up @@ -150,4 +149,4 @@ On the `main` branch:

Verify that the pattern library is working as you expect it to on your local build.

8. Upload the latest version to PyPI (requires credentials, ask someone named in `pyproject.toml` authors): `poetry publish`
8. Upload the latest version to PyPI (requires credentials, ask someone named in the [maintainers listed on PyPI](https://pypi.org/project/django-pattern-library/)): `poetry publish`
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ ENV PATH=/venv/bin:/home/dpl/.local/bin:$PATH \

USER dpl

RUN pip install --user "poetry>=1.1.12,<2" && \
RUN pip install --user "poetry>=2.1.2,<3" && \
python -m venv /venv/

COPY pyproject.toml ./
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ This package automates the maintenance of UI pattern libraries or styleguides fo
- Create reusable patterns by creating Django templates files as usual.
- All patterns automatically show up in the pattern library’s interface.
- Define data as YAML files for the templates to render with the relevant Django context.
- Override Django templates tags as needed to mock the template’s dependencies.
- Override Django Templates tags as needed to mock the template’s dependencies.
- Document your patterns with Markdown.
- Experimental: support for Jinja templates.

## Why you need this

Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ services:

frontend:
command: npm start
image: node:16
image: node:23
user: node
volumes:
- type: bind
Expand Down
20 changes: 13 additions & 7 deletions docs/community/related-projects.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,25 @@ Here are other projects that are related to django-pattern-library, and may be r

## Complementary packages

- [storybook-django](https://github.com/torchbox/storybook-django) – attempting to bridge the gap between React and Django, by bringing django-pattern-library patterns into Storybook stories.
- [django-components](https://github.com/EmilStenstrom/django-components/) – Reusable UI components for Django, going further than template partials.
- [django-component-tags](https://github.com/syse-i/django-component-tags) – Create advanced HTML components using Django Tags.
To create and reuse components within Django templates:

- [django-components](https://github.com/django-components/django-components) – Reusable UI components for Django, going further than template partials.
- [slippers](https://github.com/mixxorz/slippers) – Reusable components for Django, without writing a single line of Python.
- (Jinja only, incompatible but interesting) [JinjaX](https://jinjax.scaletti.dev/) – Write server-side components as single Jinja template files. Use them as HTML tags without doing any importing.
- [JinjaX](https://jinjax.scaletti.dev/) – Write server-side components as single Jinja template files. Use them as HTML tags without doing any importing.
- [django-viewcomponent](https://github.com/rails-inspire-django/django-viewcomponent) - Build reusable components in Django, inspired by Rails ViewComponent, the components built by django-viewcomponent can be used in both Django template or Python code.
- [django-bird](https://github.com/joshuadavidthomas/django-bird) - reusable components in Django inspired by Flux from Laravel.
- [dj-angles](https://github.com/adamghill/dj-angles) - HTML-like elements in Django templates in place of partials and tags.
- [django-cotton](https://github.com/wrabit/django-cotton)- HTML-like syntax for Django template tags

Tooling leveraging component-driven development:

- [storybook-django](https://github.com/torchbox/storybook-django) – attempting to bridge the gap between React and Django, by bringing django-pattern-library patterns into Storybook stories.

## Alternatives

- [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.
- [Pattern Lab](http://patternlab.io/) – PHP or Node pattern library, from which this project is heavily inspired.
- [Astrum](http://astrum.nodividestudio.com/) – Similar to Pattern Lab, Node based.
- [rikki-patterns](https://github.com/springload/rikki-patterns) – Experimental Django-friendly pattern library generator, for Jinja2 and Nunjucks templates

- [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.

## Pattern libraries based on Django

Expand Down
2 changes: 1 addition & 1 deletion docs/community/security-policy.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ This project doesn’t have formal support targets for non-latest versions. Back

### Reporting a vulnerability

To report a vulnerability, please contact any one of the named authors in the package’s [pyproject.toml](https://github.com/torchbox/django-pattern-library/blob/main/pyproject.toml).
To report a vulnerability, please contact any one of the [maintainers listed on PyPI](https://pypi.org/project/django-pattern-library/).
13 changes: 11 additions & 2 deletions docs/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ We support:

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

## Configuration
Expand All @@ -36,7 +36,7 @@ INSTALLED_APPS = [
]
```

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

```python hl_lines="13 14 15"
TEMPLATES = [
Expand All @@ -59,6 +59,15 @@ TEMPLATES = [
]
```

Experimental: for Jinja support, call `override_jinja_tags` in the file that contains your Jinja environment:

```python
from pattern_library.monkey_utils import override_jinja_tags

if apps.is_installed("pattern_library"):
override_jinja_tags()
```

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:

```python
Expand Down
7 changes: 5 additions & 2 deletions docs/guides/automated-tests.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ Here is a practical example of combining [Pa11y](https://pa11y.org/) and django-

```yaml
static:
image: node:16
image: node:22
stage: build
script:
- npm ci
Expand Down Expand Up @@ -182,7 +182,10 @@ let urls = [];
// In CI mode, retrieve the URLs to test from dpl-rendered-patterns.
if (process.env.CI) {
const list = path.join(__dirname, "dpl-rendered-patterns", "dpl-list.txt");
const patterns = fs.readFileSync(list, "utf-8").split("\n").filter((p) => p);
const patterns = fs
.readFileSync(list, "utf-8")
.split("\n")
.filter((p) => p);

urls = patterns.map((p) => `${origin}/${p.replace("patterns/", "")}`);
}
Expand Down
14 changes: 7 additions & 7 deletions docs/guides/overriding-template-tags.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
# Overriding template tags

The package overrides the following Django tags:
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.

- `{% extends %}`
- `{% include %}`
---

It's required to allow us to define fake template context and override other template tags in YAML files.
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.

The override process has two parts:
We can also override other template tags in YAML files. The override process has two parts:

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

!!! warning "No Jinja support"

Overriding arbitrary template tags or functions is currently unsupported for Jinja templates.

## Providing a default value for template tags

To provide a default for a template tag, you need to provide a keyword argument default_html when overriding your tag.
Expand Down
3 changes: 2 additions & 1 deletion docs/guides/usage-tips.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ You may also consider using the [`render_patterns` command](../reference/api.md#

## Document your patterns

Patterns support defining a custom `name` in YAML, as well as rendering fully-fledged documentation in Markdown. Create a file next to the template to document it:
Patterns support defining a custom `name` in YAML, as well as rendering fully-fledged documentation in Markdown. Create a file next to the template to document it, ensuring the filename has a `.md` extension (e.g., `call_to_action.md`):


```markdown
This template can be used in different places. In streamfield block
Expand Down
4 changes: 2 additions & 2 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ The [django-pattern-library](https://pypi.org/project/django-pattern-library/) p
- Create reusable patterns by creating Django templates files as usual.
- All patterns automatically show up in the pattern library’s interface.
- Define data as YAML files for the templates to render with the relevant Django context.
- Override Django templates tags as needed to mock the template’s dependencies.
- Override Django Templates tags as needed to mock the template’s dependencies.
- Document your patterns with Markdown.
- Experimental: support for Jinja templates.

Here is a screenshot of the pattern library in action:

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

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

13 changes: 12 additions & 1 deletion docs/reference/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ context:
- 2
- 3
# Mapping from tag names to tag overrides.
# Currently unsupported for Jinja templates.
tags:
error_tag:
include:
Expand Down Expand Up @@ -135,14 +136,24 @@ PATTERN_LIBRARY = {

### `override_tag`

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.
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.

```python
from pattern_library.monkey_utils import override_tag

override_tag(register, 'a_tag_name', default_html="https://example.com/")
```

### `override_jinja_tags`

🚧 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.

```python
from pattern_library.monkey_utils import override_jinja_tags

override_jinja_tags()
```

## `register_context_modifier`

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.
Expand Down
10 changes: 7 additions & 3 deletions docs/reference/known-issues.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ django-pattern-library has a few known limitations due to its design, which are

## Overriding filters is not supported

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

## Can’t override context in a child template

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

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

## Jinja2 support
## Jinja2 overrides

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).
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).

## Past limitations

### Jinja2 support

🎉 This is now addressed as of v1.5.0, though with only experimental support, and no capability to override tags, functions, filters (see above).

### No way to specify objects that have attributes and support iteration

🎉 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.
Expand Down
Loading