added support for jinja assets tag

This commit is contained in:
Christopher Pickering 2021-08-19 10:52:50 -05:00
parent dcb1892e00
commit e6b9a9da1b
No known key found for this signature in database
GPG key ID: E14DB3B0A0FACF84
2 changed files with 21 additions and 5 deletions

View file

@ -15,7 +15,7 @@ ignored_tag_opening = r"<script|<style|<!--|{\*|<\?php|<pre"
ignored_tag_closing = r"</script|</style|-->|\*}|\?>|</pre"
# the contents of these tag blocks will be indented
tag_indent = r"(?:\{\{\#)|\{% +?(if|for|block|else|spaceless|compress|addto|language|with)|(?:{% verbatim %})|(?:<(?:html|head|body|div|a|nav|ul|ol|dl|li|table|thead|tbody|tr|th|td|blockquote|textarea|select|form|option|cache|optgroup|fieldset|legend|label|header|main|section|aside|footer|figure|video|span|p|g|svg|h\d|button|img|path|script|style|source))"
tag_indent = r"(?:\{\{\#)|\{% +?(if|for|block|else|spaceless|compress|addto|language|with|assets)|(?:{% verbatim %})|(?:<(?:html|head|body|div|a|nav|ul|ol|dl|li|table|thead|tbody|tr|th|td|blockquote|textarea|select|form|option|cache|optgroup|fieldset|legend|label|header|main|section|aside|footer|figure|video|span|p|g|svg|h\d|button|img|path|script|style|source))"
# this signals when tags should be unindented (see tags above)
tag_unindent = r"(?:\{\{\/)|\{% end|(?:{% endverbatim %})|(?:</(?:html|head|body|div|a|nav|ul|ol|dl|li|table|thead|tbody|tr|th|td|blockquote|select|form|option|optgroup|fieldset|legend|label|textarea|header|cache|main|section|aside|footer|figure|video|span|p|g|svg|h\d|button|img|path|script|style|source))"
@ -66,12 +66,10 @@ ignored_paths = [
"__pypackages__",
]
start_template_tags = (
r"{% ?(?:if|for|block|spaceless|compress|load|assets|addto|language|with)[^}]+?%}"
)
start_template_tags = r"{% ?(?:if|for|block|spaceless|compress|load|assets|addto|language|with|assets)[^}]+?%}"
break_template_tags = [
r"{% ?(?:if|end|for|block|endblock|else|spaceless|compress|load|include|assets|addto|language|with)[^}]+?%}",
r"{% ?(?:if|end|for|block|endblock|else|spaceless|compress|load|include|assets|addto|language|with|assets)[^}]+?%}",
]
unformated_html_tags = ["script"]

View file

@ -276,3 +276,21 @@ def test_check_reformatter_no_error(runner, tmp_file):
result = runner.invoke(djlint, [tmp_file.name, "--check"])
assert result.exit_code == 0
assert "0 files would be updated." in result.output
def test_reformat_asset_tag(runner, tmp_file):
write_to_file(
tmp_file.name,
b"""{% block css %}{% assets "css_error" %}<link type="text/css" rel="stylesheet" href="{{ ASSET_URL }}" />{% endassets %}{% endblock css %}""",
)
result = runner.invoke(djlint, [tmp_file.name, "--reformat"])
assert (
open(tmp_file.name).read()
== """{% block css %}
{% assets "css_error" %}
<link type="text/css" rel="stylesheet" href="{{ ASSET_URL }}" />
{% endassets %}
{% endblock css %}
"""
)
assert result.exit_code == 1