Skip to content

Commit fda5741

Browse files
committed
Add basic Jinja tests
1 parent f7d2963 commit fda5741

35 files changed

+330
-10
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@ This package automates the maintenance of UI pattern libraries or styleguides fo
1313
- Create reusable patterns by creating Django templates files as usual.
1414
- All patterns automatically show up in the pattern library’s interface.
1515
- Define data as YAML files for the templates to render with the relevant Django context.
16-
- Override Django templates tags as needed to mock the template’s dependencies.
16+
- Override Django Templates tags as needed to mock the template’s dependencies.
1717
- Document your patterns with Markdown.
18+
- Experimental: support for Jinja templates.
1819

1920
## Why you need this
2021

pattern_library/monkey_utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ def node_render(context):
126126

127127
def override_jinja_tags():
128128
"""
129-
Overrides jinja extends and include tags for use in your pattern library.
129+
Experimental. Overrides jinja extends and include tags for use in your pattern library.
130130
Call it in your settings to override tags
131131
"""
132132
global jinja_visit_Extends
@@ -136,7 +136,7 @@ def override_jinja_tags():
136136
except ModuleNotFoundError:
137137
ModuleNotFoundError("install jinja2 to override jinja tags")
138138

139-
from .loader_tags import template_new_context, visit_extends
139+
from pattern_library.loader_tags import template_new_context, visit_extends
140140

141141
jinja_visit_Extends = JinjaCodeGenerator.visit_Extends
142142
JinjaTemplate.new_context = template_new_context

pattern_library/utils.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,6 @@ def get_template_ancestors(cls, template_name, context=None, ancestors=None):
307307
context = Context()
308308

309309
pattern_template = get_template(template_name)
310-
# todo - make sure envrionment has context passed in
311310
environment = pattern_template.template.environment
312311
nodelist = environment.parse(pattern_template.template.name)
313312
parent_template_name = nodelist.find(Extends)

tests/jinja/non-patterns/include.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
SHOWME
2+
{% if False %}
3+
HIDEME
4+
{% endif %}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
included content from variable
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<!doctype html>
2+
<html lang="en-GB">
3+
<head>
4+
<meta charset="utf-8" />
5+
<title>{% block title %}Fragment{% endblock %}</title>
6+
<meta name="viewport" content="width=device-width, initial-scale=1" />
7+
8+
<link rel="stylesheet" href="{{ static('main.css') }}">
9+
</head>
10+
<body>
11+
<main>
12+
{% block content %}{% endblock %}
13+
</main>
14+
<script src="{{ static('main.js') }}"></script>
15+
</body>
16+
</html>
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{% extends 'patterns_jinja/base_jinja.html' %}
2+
3+
{% block title %}{{ page.title }}{% endblock %}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<div class="accordion" data-accordion>
2+
{% for accordion in accordions %}
3+
<div class="accordion__panel" data-accordion-panel>
4+
<h3 class="accordion__title heading heading--4">
5+
<button class="accordion__toggle" type="button" data-accordion-toggle aria-pressed="true" aria-expanded="true" aria-controls="{{ id_prefix }}-content-{{ loop.index }}">
6+
<span class="accordion__title-inner">{{ accordion.title }}</span>
7+
{% set name="chevron-down" %}
8+
{% set classname="accordion__icon" %}
9+
{% include "patterns_jinja/components/icons/icon.html" %}
10+
</button>
11+
</h3>
12+
<div id="{{ id_prefix }}-content-{{ loop.index }}" class="accordion__content" data-accordion-content>
13+
<p>{{ accordion.description }}</p>
14+
</div>
15+
</div>
16+
{% endfor %}
17+
</div>
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Accordion (Jinja)
2+
3+
The accordion is a good example of a pattern library component. This one uses [Jinja](https://jinja.palletsprojects.com/).
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
context:
2+
id_prefix: test
3+
accordions:
4+
- title: Title A (Jinja)
5+
description: Description A. Ask for help.
6+
- title: Title B
7+
description: Description B. Ask for help.
8+
- title: Title C
9+
description: Description C. Ask for help.
10+
- title: Title D
11+
description: Description D. Ask for help.

0 commit comments

Comments
 (0)