Skip to content

Commit

Permalink
feat(formatter): added support for symphony forms
Browse files Browse the repository at this point in the history
closes #476
  • Loading branch information
christopherpickering committed Jun 12, 2023
1 parent 07c690b commit e716ddc
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/djlint/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -537,13 +537,15 @@ def __init__(
("""
+ self.indent_template_tags
+ r"""
)"""
) | \{{-?[ ]*?form_start
"""
)

self.template_unindent: str = r"""
(?:
(?:\{\{\/)
| (?:\{%-?[ ]*?end(?!comment))
| (?:\{{-?[ ]*?form_end)
)
"""

Expand Down
39 changes: 39 additions & 0 deletions tests/test_twig/test_symfony.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
"""Test twig symfony form tags.
poetry run pytest tests/test_twig/test_symfony.py
"""
import pytest

from src.djlint.reformat import formatter
from tests.conftest import printer

test_data = [
pytest.param(
(
"{{ form_start(form) }}\n"
" {{ form_widget(form) }}\n"
"\n"
' <button type="submit" class="btn btn-primary">\n'
' <i class="fa fa-save" aria-hidden="true"></i> {{ \'action.save\'|trans }}\n'
" </button>\n"
" {{ form_end(form) }}"
),
(
"{{ form_start(form) }}\n"
" {{ form_widget(form) }}\n"
' <button type="submit" class="btn btn-primary">\n'
' <i class="fa fa-save" aria-hidden="true"></i> {{ \'action.save\'|trans }}\n'
" </button>\n"
"{{ form_end(form) }}\n"
),
id="comments",
),
]


@pytest.mark.parametrize(("source", "expected"), test_data)
def test_base(source, expected, nunjucks_config):
output = formatter(nunjucks_config, source)

printer(expected, source, output)
assert expected == output

0 comments on commit e716ddc

Please sign in to comment.