Skip to content
This repository has been archived by the owner on Jun 24, 2024. It is now read-only.

Enable Jinja2 whitespace control by default #44

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

m000
Copy link

@m000 m000 commented Jul 28, 2019

This patch turns on Jinja2 whitespace control by default. This will greatly reduce the need to use manual whitespace control in the templates in order to produce good looking output.

Rationale:
Jinja2 on the web: The common use of Jinja2 is to serve web requests in realtime. The rendered templates are rarely inspected by a human and have a lifetime of a few minutes (at best). In this context, it is reasonable to turn off whitespace control to save some processing time and maximize throughput.
Jinja2 on j2cli: j2cli is meant mostly as a batch processing tool. I.e. it is invoked only periodically. The generated output persists for much longer, and it is quite likely to be inspected by a human. Therefore, enabling whitespace control by default to produce better looking output makes
sense.

Side-effects:
There are barely any side-effects from this patch. Where manual space control is used in templates (e.g. {%- ... -%}) the - modifiers will become redundant. They can be eventually removed at a time of convenience.
The only side-effect I've noticed is the case of consecutive {% include ... %} tags. In this case, whitespace control needs to be manually disabled using the + modifier. E.g. this:

{% include 'include/a.inc' %}
{% include 'include/b.inc' %}

becomes:

{%+ include 'include/a.inc' %}
{%+ include 'include/b.inc' %}

But I love whitespace in my output:
In case someone absolutely hates this behaviour, it can be turned off with the new --no-compact flag.

m000 added 3 commits July 28, 2019 01:33
turned of with the --no-compact flag.
See: http://jinja.pocoo.org/docs/2.10/templates/#whitespace-control

Rationale:
The common use of Jinja2 is to serve web requests in realtime. In this
context, it is reasonable to turn off whitespace control to save some
processing time.
However, j2cli is meant mostly as a batch processing tool. I.e. it is
invoked periodically, the generated output persists for much longer,
and it is more likely to be inspected by a human. Therefore, enabling
whitespace control by default to produce better looking output makes
sense.
@m000 m000 changed the title Enable by default Enable Jinja2 whitespace control by default Jul 28, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant