From fe5dfa9d451bb252c094a84b0044b2a33dea4a68 Mon Sep 17 00:00:00 2001 From: Jordy Boer Date: Wed, 22 Jan 2025 17:14:54 +0100 Subject: [PATCH] Fix: indentation for handlebars unless --- djlint/settings.py | 4 +++ tests/test_handlebars/test_unless.py | 50 ++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+) create mode 100644 tests/test_handlebars/test_unless.py diff --git a/djlint/settings.py b/djlint/settings.py index 47b23a374..bae77c416 100644 --- a/djlint/settings.py +++ b/djlint/settings.py @@ -603,6 +603,7 @@ def __init__( self.indent_template_tags: str = ( (rf"(?!{self.ignore_blocks})" if self.ignore_blocks else "") + r""" (?:if + | unless | ifchanged | for | asyncEach @@ -788,6 +789,7 @@ def __init__( (rf"(?!{self.ignore_blocks})" if self.ignore_blocks else "") + r""" (?:if + | unless | for | asyncEach | asyncAll @@ -822,6 +824,7 @@ def __init__( (rf"(?!{self.ignore_blocks})" if self.ignore_blocks else "") + r""" (?:if + | unless | endif | for | endfor @@ -1027,6 +1030,7 @@ def __init__( self.optional_single_line_template_tags: str = r""" if | for + | unless | block | with | asyncEach diff --git a/tests/test_handlebars/test_unless.py b/tests/test_handlebars/test_unless.py new file mode 100644 index 000000000..2175846e7 --- /dev/null +++ b/tests/test_handlebars/test_unless.py @@ -0,0 +1,50 @@ +"""Test handlebars each tag. + +uv run pytest tests/test_handlebars/test_each.py +""" + +from __future__ import annotations + +from typing import TYPE_CHECKING + +import pytest + +from djlint.reformat import formatter +from tests.conftest import printer + +if TYPE_CHECKING: + from djlint.settings import Config + +test_data = [ + pytest.param( + ( + " {{#unless}}

{{/unless}}" + ), + ( + "\n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " {{#unless}}\n" + "
\n" + "

\n" + "
\n" + " {{/unless}}\n" + " \n" + "\n" + ), + id="unless_tag", + ) +] + + +@pytest.mark.parametrize(("source", "expected"), test_data) +def test_base(source: str, expected: str, handlebars_config: Config) -> None: + output = formatter(handlebars_config, source) + + printer(expected, source, output) + assert expected == output