Skip to content

Commit

Permalink
Fix: indentation for handlebars unless (#1114)
Browse files Browse the repository at this point in the history
Co-authored-by: Jordy Boer <[email protected]>
  • Loading branch information
S1mplePixels and Jordy Boer authored Feb 13, 2025
1 parent a2d69bb commit d97b7e0
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/djlint/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -788,6 +789,7 @@ def __init__(
(rf"(?!{self.ignore_blocks})" if self.ignore_blocks else "")
+ r"""
(?:if
| unless
| for
| asyncEach
| asyncAll
Expand Down Expand Up @@ -822,6 +824,7 @@ def __init__(
(rf"(?!{self.ignore_blocks})" if self.ignore_blocks else "")
+ r"""
(?:if
| unless
| endif
| for
| endfor
Expand Down Expand Up @@ -1027,6 +1030,7 @@ def __init__(
self.optional_single_line_template_tags: str = r"""
if
| for
| unless
| block
| with
| asyncEach
Expand Down
50 changes: 50 additions & 0 deletions tests/test_handlebars/test_unless.py
Original file line number Diff line number Diff line change
@@ -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(
(
"<html lang='en'> <head> <meta charset='UTF-8' /> <meta name='viewport' content='width=device-width, initial-scale=1' /> <title></title> <link href='css/style.css' rel='stylesheet' /> </head> <body> {{#unless}} <div> <p></p> </div> {{/unless}}</body></html>"
),
(
"<html lang='en'>\n"
" <head>\n"
" <meta charset='UTF-8' />\n"
" <meta name='viewport' content='width=device-width, initial-scale=1' />\n"
" <title></title>\n"
" <link href='css/style.css' rel='stylesheet' />\n"
" </head>\n"
" <body>\n"
" {{#unless}}\n"
" <div>\n"
" <p></p>\n"
" </div>\n"
" {{/unless}}\n"
" </body>\n"
"</html>\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

0 comments on commit d97b7e0

Please sign in to comment.