Skip to content

Django template tags which deal with pesky whitespaces!

License

Notifications You must be signed in to change notification settings

denizdogan/django-whiteless

Repository files navigation

django-whiteless

Django template tags which deal with pesky whitespaces!

Travis (.org)

  • Django 2.x and 3.x
  • Python 3.7, 3.8, 3.9

Installation

Install the latest version from PyPI:

$ pip install django-whiteless

Add "whiteless" to INSTALLED_APPS:

INSTALLED_APPS = (
    # ...
    "whiteless",
)

Usage

The library consists of two template tags, {% whiteless %} and {% eof %}. This is how you use them.

Remove all whitespaces

{% whiteless %}
    ...
{% endwhiteless %}

Remove leading whitespaces

{% whiteless leading %}
    ...
{% endwhiteless %}

Remove trailing whitespaces

{% whiteless trailing %}
    ...
{% endwhiteless %}

Remove leading and trailing whitespaces

{% whiteless leading trailing %}
    ...
{% endwhiteless %}

Replace whitespaces with a single space

{% whiteless space %}
    ...
{% endwhiteless %}

Note 1: If there are leading or trailing whitespaces in the block, those will also be replaced by a single space. In order to remove leading and trailing whitespaces and replace all other whitespaces with a single space, use: {% whiteless space leading trailing %}

Note 2: If used within a for-loop, the example will leave a space before and after each iteration. In other words, there will be two spaces between each part.

Remove trailing whitespaces at end of file

Hello there!{% eof %}

This is useful if e.g. your project style guide requires all files to end with a newline but that causes issues with your template.

Note that {% eof %} cannot be used inside other tags. It only removes whitespaces that immediately follow itself.

Development

$ poetry shell
$ poetry install
$ pre-commit install  # install git hooks
$ tox  # run tests

License

MIT

About

Django template tags which deal with pesky whitespaces!

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages