Skip to main content

A Django template formatter.

Project description

https://img.shields.io/github/actions/workflow/status/adamchainz/djade/main.yml.svg?branch=main&style=for-the-badge https://img.shields.io/badge/Coverage-100%25-success?style=for-the-badge https://img.shields.io/pypi/v/djade.svg?style=for-the-badge https://img.shields.io/badge/code%20style-black-000000.svg?style=for-the-badge pre-commit
Any color you like, as long as it’s jade.

A Django template formatter.


Improve your Django and Git skills with my books.


Installation

Use pip:

python -m pip install djade

Python 3.8 to 3.13 supported.

Usage

djade is a commandline tool that rewrites files in place. Run it on a file to modify it:

djade templates/index.html

Djade implements some rules listed in the Django contribution style guide’s template style section:

  • One space around variables and tags:

    -{{egg}}
    +{{ egg }}
    
    -{%  crack egg  %}
    +{% crack egg %}
  • Add labels to {% endblock %} tags that aren’t on the same line as their opening {% block %} tag:

     {% block shell %}
     ...
    -{% endblock %}
    +{% endblock shell %}
  • In {% load %} tags, alphabetically sort libraries:

    -{% load omelette frittata %}
    +{% load friattata omelette %}

Djade also implements some extra rules:

  • Leading empty lines are removed:

    -
     {% extends 'white.html' %}
     ...
  • Trailing empty lines are removed, and a trailing newline inserted if necessary:

     ...
     {% endblock content %}
    -
    -
  • One space around comment tags:

    -{#egg#}
    +{# egg #}
  • Remove labels from {% endblock %} tags on the same line as their opening {% block %} tag:

    -{% block shell %}...{% endblock shell %}
    +{% block shell %}...{% endblock %}
  • Merge consecutive {% load %} tags:

    -{% load omelette %}
    -
    -{% load frittata %}
    +{% load frittata omelette %}

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

djade-0.1.0.tar.gz (19.4 kB view hashes)

Uploaded Source

Built Distributions

djade-0.1.0-py3-none-win_arm64.whl (802.8 kB view hashes)

Uploaded Python 3 Windows ARM64

djade-0.1.0-py3-none-win_amd64.whl (877.4 kB view hashes)

Uploaded Python 3 Windows x86-64

djade-0.1.0-py3-none-win32.whl (795.8 kB view hashes)

Uploaded Python 3 Windows x86

djade-0.1.0-py3-none-musllinux_1_1_x86_64.whl (1.2 MB view hashes)

Uploaded Python 3 musllinux: musl 1.1+ x86-64

djade-0.1.0-py3-none-musllinux_1_1_aarch64.whl (1.1 MB view hashes)

Uploaded Python 3 musllinux: musl 1.1+ ARM64

djade-0.1.0-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.1 MB view hashes)

Uploaded Python 3 manylinux: glibc 2.17+ x86-64

djade-0.1.0-py3-none-manylinux_2_17_i686.manylinux2014_i686.whl (1.2 MB view hashes)

Uploaded Python 3 manylinux: glibc 2.17+ i686

djade-0.1.0-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (1.1 MB view hashes)

Uploaded Python 3 manylinux: glibc 2.17+ ARMv7l

djade-0.1.0-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (1.1 MB view hashes)

Uploaded Python 3 manylinux: glibc 2.17+ ARM64

djade-0.1.0-py3-none-macosx_11_0_arm64.whl (982.6 kB view hashes)

Uploaded Python 3 macOS 11.0+ ARM64

djade-0.1.0-py3-none-macosx_10_12_x86_64.whl (1.0 MB view hashes)

Uploaded Python 3 macOS 10.12+ x86-64

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