Skip to main content

Django template tags for dealing with pesky whitespaces

Project description

django-whiteless

Django template tags which deal with pesky whitespaces!

CircleCI

  • 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 that 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 %}
    ...
{% endwhiteless %}

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django-whiteless-1.0.0.tar.gz (4.7 kB view hashes)

Uploaded Source

Built Distribution

django_whiteless-1.0.0-py3-none-any.whl (5.6 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page