Skip to content

Commit eaee00b

Browse files
committed
docs fix code examples
1 parent f34f4d1 commit eaee00b

File tree

2 files changed

+17
-21
lines changed

2 files changed

+17
-21
lines changed

docs/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
- [Is Ontospy for Me?](#is-ontospy-for-me)
1111
- [Generating Ontology Documentation](#generating-ontology-documentation)
1212
- [Miscellaneous Tips](#miscellaneous-tips)
13+
- [Version 2 Upgrade](#upgrading-to-v-2.0)
1314
- [Quick Links](#quick-links)
1415

1516
## Welcome to Ontospy's Documentation!

docs/pages/django-to-jinja.md

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ This is to make Ontospy footprint more lightweight, as well as to simplify futur
66

77
This page contains information of Django specific template filters, or constructs, that are not directly usable with Jinja and how they have been updated.
88

9+
{% raw %}
910

1011
## NOW
1112

@@ -14,9 +15,7 @@ Django's template tag `now` can be used in Jinja after installing the extension
1415
Then you can do
1516

1617
```python
17-
{% raw %}
1818
{% now 'utc', '%a, %d %b %Y %H:%M:%S' %}
19-
{% endraw %}
2019
```
2120

2221

@@ -27,21 +26,18 @@ Django's template tag `ifchanged` does not exist in Jinja. So a custom logic for
2726
From
2827

2928
```python
30-
{% raw %}
3129
{% for each in o.annotations %}
3230
{% ifchanged each.1 %}
3331
{% if not forloop.first %}</dl>{% endif %}
3432
<dt>{{each.1}}</dt>
3533
{% endifchanged %}
3634
<dd>{{each.2|linebreaks}}</dd>
3735
{% endfor %}
38-
{% endraw %}
3936
```
4037

4138
To
4239

4340
```python
44-
{% raw %}
4541
{% for each in o.annotations() %}
4642
{% if each.1 != variable_watcher %}
4743
{% if not loop.first %}</dl>{% endif %}
@@ -51,7 +47,6 @@ To
5147
{% endif %}
5248
<dd>{{each.2|linebreaks}}</dd>
5349
{% endfor %}
54-
{% endraw %}
5550
```
5651

5752

@@ -60,7 +55,7 @@ To
6055
Django's template tag `ifchanged` has a slightly diffent syntax in [Jinja](https://jinja.palletsprojects.com/en/3.1.x/templates/#jinja-filters.default).
6156

6257
From
63-
{% raw %}
58+
6459
```python
6560
{{s.qname|default:each.qname}}
6661
```
@@ -69,13 +64,13 @@ To
6964
```python
7065
{{s.qname|default(each.qname)}}
7166
```
72-
{% endraw %}
67+
7368

7469
## LINEBREAKS
7570

7671
Django's template filter `linebreaks` does not exist in Jinja. It can be implemented as a custom filter (see this [thread on SO](https://stackoverflow.com/questions/4901483/how-to-apply-django-jinja2-template-filters-escape-and-linebreaks-correctly))
7772

78-
{% raw %}
73+
7974
```python
8075
import re
8176
from markupsafe import Markup, escape
@@ -93,57 +88,57 @@ def linebreaks_filter(eval_ctx, value):
9388

9489
env.filters['linebreaks'] = linebreaks_filter
9590
```
96-
{% endraw %}
91+
9792

9893
## METHOD CALLS
9994

10095
Django's templating language is 'relaxed' when it comes to resolving an object *attribute* or *method* call. In both cases, it's enough to pass the *attribute* or *method* name.
10196

10297
With Jinja, *method* calls need to be followed by parentheses, like in Python. See also https://stackoverflow.com/questions/59589889/difference-between-an-item-and-an-attribute-jinja-python
10398

104-
{% raw %}
99+
105100
From
106101
```python
107-
"""{% for each in o.annotations %}"""
102+
{% for each in o.annotations %}
108103
```
109104

110105
To
111106
```python
112-
"""{% for each in o.annotations() %}"""
107+
{% for each in o.annotations() %}
113108
```
114-
{% endraw %}
109+
115110

116111
PS this applies to `each.children()` , `each.parents()`, `each.rdf_source()` etc..
117112

118113

119-
{% raw %}
114+
120115
## IFEQUAL
121116

122117
From
123118

124119
```python
125-
"""{% ifequal objtype "class" #}"""
120+
{% ifequal objtype "class" #}"""
126121
```
127122

128123
To
129124

130125
```python
131-
"""{% if objtype == "class" #}"""
126+
{% if objtype == "class" #}"""
132127
```
133128

134129
## WITH
135130

136131
From
137132
```python
138-
"""{% with main_entity as each #}"""
133+
{% with main_entity as each #}"""
139134
...
140135
{% endwith %}
141136
```
142137

143138
To
144139

145140
```python
146-
"""{% set each = main_entity #}"""
141+
{% set each = main_entity #}"""
147142
# no need to close anything
148143
```
149144

@@ -154,13 +149,13 @@ See https://jinja.palletsprojects.com/en/3.1.x/templates/#comments
154149
From
155150

156151
```python
157-
"""{% comment %}
152+
{% comment %}
158153
```
159154

160155
To
161156

162157
```python
163-
"""{%
158+
{%
164159
comment
165160
#}"""
166161
```

0 commit comments

Comments
 (0)