You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A module for Django that helps you to build pattern libraries.
7
6
8
7

9
8
10
9
## Documentation
11
10
12
-
Documentation is located in GitHub in [`docs/`](https://github.com/torchbox/django-pattern-library/tree/master/docs).
11
+
Documentation is located on GitHub in [`docs/`](https://github.com/torchbox/django-pattern-library/tree/master/docs).
13
12
14
13
## Objective
15
14
@@ -29,9 +28,38 @@ To learn more about how this package can be used, have a look at our Wagtail Spa
29
28
30
29
[](https://www.youtube.com/watch?v=isrOufI7TKc)
31
30
31
+
## Concepts
32
+
To understand how `django-pattern-library` works, the following concepts are important.
33
+
34
+
### Patterns
35
+
Any template that is displayed by the pattern library is referred to as a pattern. Patterns are divided into two categories: fragments and pages.
36
+
37
+
### Fragments
38
+
A fragment is a pattern whose markup does not include all of the resources (typically CSS and Javascript) for it to be displayed correctly on its own. This is typical for reusable component templates which depend on global stylesheets or Javascript bundles to render and behave correctly.
39
+
40
+
To enable them to be correctly displayed in the pattern library, `django-pattern-library` will inject the rendered markup of fragments into the **pattern base template** specified by `PATTERN_LIBRARY['PATTERN_BASE_TEMPLATE_NAME']`.
41
+
42
+
This template should include references to any required static files. The rendered markup of fragments will be available in the `pattern_library_rendered_pattern` context variable (see the tests for [an example](https://github.com/torchbox/django-pattern-library/blob/master/tests/templates/patterns/base.html)).
43
+
44
+
### Pages
45
+
In contrast to fragments, pages are patterns that include everything they need to be displayed correctly in their markup. Pages are defined by `PATTERN_LIBRARY['BASE_TEMPLATE_NAMES']`.
46
+
47
+
Any template in that list — or that extends a template in that list — is considered a page and will be displayed as-is when rendered in the pattern library.
48
+
49
+
It is common practice for page templates to extend the pattern base template to avoid duplicate references to stylesheets and Javascript bundles. Again, [an example](https://github.com/torchbox/django-pattern-library/blob/master/tests/templates/patterns/base_page.html) of this can be seen in the tests.
50
+
32
51
## How to install
33
52
34
-
In your Django settings, add `pattern_library` into your `INSTALLED_APPS`, and `pattern_library.loader_tags` into the `TEMPLATES` setting. For example:
53
+
First install the library:
54
+
55
+
```sh
56
+
pip install django-pattern-library
57
+
# ... or...
58
+
poetry add django-pattern-library
59
+
```
60
+
61
+
62
+
Then, in your Django settings, add `pattern_library` into your `INSTALLED_APPS`, and `pattern_library.loader_tags` to `OPTIONS['builtins']` into the `TEMPLATES` setting. For example:
35
63
36
64
```python
37
65
INSTALLED_APPS= [
@@ -58,18 +86,42 @@ TEMPLATES = [
58
86
]
59
87
```
60
88
61
-
Note that this module only supports the Django template backend out of the box.
89
+
Note that this module only supports the Django template backend.
62
90
63
-
Set the `PATTERN_LIBRARY_TEMPLATE_DIR` setting to point to a template directory with your patterns:
91
+
### Settings
92
+
93
+
Next, set the `PATTERN_LIBRARY` setting. Here's an example showing the defaults:
0 commit comments