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 details)

Uploaded Source

Built Distribution

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

Uploaded Python 3

File details

Details for the file django-whiteless-1.0.0.tar.gz.

File metadata

  • Download URL: django-whiteless-1.0.0.tar.gz
  • Upload date:
  • Size: 4.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.6 CPython/3.9.3 Darwin/20.4.0

File hashes

Hashes for django-whiteless-1.0.0.tar.gz
Algorithm Hash digest
SHA256 940655f8d8adda47db7c086f32ae7ed8be7bb67efefa04abf47b7a53e5f293a5
MD5 76d6a4cdc91ee757f115f75f7e211fbe
BLAKE2b-256 7234b59e5c512b67b6efdd1ca06f95fbde89dd7848dfc6cdd9e7793eb5180107

See more details on using hashes here.

File details

Details for the file django_whiteless-1.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for django_whiteless-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1787ae27e15499f1eac7b380e5c4af45fc70364b9f15c85e0acb524f95413f76
MD5 37794d27d46dc150dc1d63de507dbafa
BLAKE2b-256 374a1c64704aa2ce10d19f142146c84a6ae4a86d7283948a0df157aee8425853

See more details on using hashes here.

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