포맷터 사용법
djLint의 포맷터는 엉성한 HTML 템플릿을 받아 일관되고 읽기 쉬운 형태로 포맷합니다!
변경 사항을 적용하기 전에 --check로 결과를 검토하세요.
포맷하면 무엇이 바뀌는지 검토하려면 다음을 실행합니다.
djlint . --check
코드를 포맷하고 파일을 업데이트하려면 다음을 실행합니다.
djlint . --reformat --single-attribute-per-line
# 스크립트와 스타일도 포맷하려면?
djlint . --reformat --single-attribute-per-line --format-css --format-js
예시를 살펴봅시다!
포맷 전
손질이 절실하게 필요한 HTML 덩어리입니다.
{% 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>
포맷 후
이제 조금 나아 보입니다… 읽을 수는 있겠네요 :)
{% 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>
single_attribute_per_line 옵션으로 포맷한 후
Prettier 스타일의 속성 배치를 선호하나요? 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>