diff --git a/docs/index.md b/docs/index.md index d6a44af..f0ed127 100644 --- a/docs/index.md +++ b/docs/index.md @@ -10,6 +10,7 @@ - [Is Ontospy for Me?](#is-ontospy-for-me) - [Generating Ontology Documentation](#generating-ontology-documentation) - [Miscellaneous Tips](#miscellaneous-tips) +- [Version 2 Upgrade](#upgrading-to-v-2.0) - [Quick Links](#quick-links) ## Welcome to Ontospy's Documentation! diff --git a/docs/pages/django-to-jinja.md b/docs/pages/django-to-jinja.md index 6e129c9..8bcc32f 100644 --- a/docs/pages/django-to-jinja.md +++ b/docs/pages/django-to-jinja.md @@ -6,6 +6,7 @@ This is to make Ontospy footprint more lightweight, as well as to simplify futur This page contains information of Django specific template filters, or constructs, that are not directly usable with Jinja and how they have been updated. +{% raw %} ## NOW @@ -14,9 +15,7 @@ Django's template tag `now` can be used in Jinja after installing the extension Then you can do ```python -{% raw %} {% now 'utc', '%a, %d %b %Y %H:%M:%S' %} -{% endraw %} ``` @@ -27,7 +26,6 @@ Django's template tag `ifchanged` does not exist in Jinja. So a custom logic for From ```python -{% raw %} {% for each in o.annotations %} {% ifchanged each.1 %} {% if not forloop.first %}{% endif %} @@ -35,13 +33,11 @@ From {% endifchanged %}
{{each.2|linebreaks}}
{% endfor %} -{% endraw %} ``` To ```python -{% raw %} {% for each in o.annotations() %} {% if each.1 != variable_watcher %} {% if not loop.first %}{% endif %} @@ -51,7 +47,6 @@ To {% endif %}
{{each.2|linebreaks}}
{% endfor %} -{% endraw %} ``` @@ -60,7 +55,7 @@ To Django's template tag `ifchanged` has a slightly diffent syntax in [Jinja](https://jinja.palletsprojects.com/en/3.1.x/templates/#jinja-filters.default). From -{% raw %} + ```python {{s.qname|default:each.qname}} ``` @@ -69,13 +64,13 @@ To ```python {{s.qname|default(each.qname)}} ``` -{% endraw %} + ## LINEBREAKS 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)) -{% raw %} + ```python import re from markupsafe import Markup, escape @@ -93,7 +88,7 @@ def linebreaks_filter(eval_ctx, value): env.filters['linebreaks'] = linebreaks_filter ``` -{% endraw %} + ## METHOD CALLS @@ -101,41 +96,41 @@ Django's templating language is 'relaxed' when it comes to resolving an object * 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 -{% raw %} + From ```python -"""{% for each in o.annotations %}""" +{% for each in o.annotations %} ``` To ```python -"""{% for each in o.annotations() %}""" +{% for each in o.annotations() %} ``` -{% endraw %} + PS this applies to `each.children()` , `each.parents()`, `each.rdf_source()` etc.. -{% raw %} + ## IFEQUAL From ```python -"""{% ifequal objtype "class" #}""" +{% ifequal objtype "class" #}""" ``` To ```python -"""{% if objtype == "class" #}""" +{% if objtype == "class" #}""" ``` ## WITH From ```python -"""{% with main_entity as each #}""" +{% with main_entity as each #}""" ... {% endwith %} ``` @@ -143,7 +138,7 @@ From To ```python -"""{% set each = main_entity #}""" +{% set each = main_entity #}""" # no need to close anything ``` @@ -154,13 +149,13 @@ See https://jinja.palletsprojects.com/en/3.1.x/templates/#comments From ```python -"""{% comment %} +{% comment %} ``` To ```python -"""{% +{% comment #}""" ```