Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: indentation for handlebars unless #1114

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions 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
Loading