Używanie formatera
Formater djLint weźmie niechlujne szablony HTML i nada im spójne, czytelne formatowanie!
Zanim zastosujesz zmiany, przejrzyj wynik za pomocą --check.
Aby sprawdzić, co może się zmienić w formatowaniu, uruchom:
djlint . --check
Aby sformatować kod i zaktualizować pliki, uruchom:
djlint . --reformat --single-attribute-per-line
# a może sformatować też skrypty i style?
djlint . --reformat --single-attribute-per-line --format-css --format-js
Oto przykład!
Przed
Oto kawałek HTML-a, który rozpaczliwie potrzebuje uwagi:
{% load admin_list %}
{% load i18n %}
<p class="paginator">
{% if pagination_required %}
{% for i in page_range %}
{% paginator_number cl i %}
{% endfor %}
{% endif %}
{{ cl.result_count }}
{% if cl.result_count == 1 %}
{{ cl.opts.verbose_name }}
{% else %}
{{ cl.opts.verbose_name_plural }}
{% endif %}
{% if show_all_url %}
<a href="{{ show_all_url }}" class="showall">{% translate 'Show all' %}</a>
{% endif %}
{% if cl.formset and cl.result_count %}
<input type="submit" name="_save" class="default" value="{% translate 'Save' %}">
{% endif %}
</p>
Po
Teraz wygląda trochę lepiej… da się to czytać :)
{% load admin_list %}
{% load i18n %}
<p class="paginator">
{% if pagination_required %}
{% for i in page_range %}
{% paginator_number cl i %}
{% endfor %}
{% endif %}
{{ cl.result_count }}
{% if cl.result_count == 1 %}
{{ cl.opts.verbose_name }}
{% else %}
{{ cl.opts.verbose_name_plural }}
{% endif %}
{% if show_all_url %}
<a href="{{ show_all_url }}" class="showall">{% translate "Show all" %}</a>
{% endif %}
{% if cl.formset and cl.result_count %}
<input type="submit"
name="_save"
class="default"
value="{% translate 'Save' %}">
{% endif %}
</p>
Po włączeniu single_attribute_per_line
Wolisz atrybuty w stylu Prettiera? Włącz opcję single_attribute_per_line:
{% load admin_list %}
{% load i18n %}
<p class="paginator">
{% if pagination_required %}
{% for i in page_range %}
{% paginator_number cl i %}
{% endfor %}
{% endif %}
{{ cl.result_count }}
{% if cl.result_count == 1 %}
{{ cl.opts.verbose_name }}
{% else %}
{{ cl.opts.verbose_name_plural }}
{% endif %}
{% if show_all_url %}
<a href="{{ show_all_url }}" class="showall">{% translate "Show all" %}</a>
{% endif %}
{% if cl.formset and cl.result_count %}
<input
type="submit"
name="_save"
class="default"
value="{% translate 'Save' %}"
>
{% endif %}
</p>