Skip to content

Commit

Permalink
feat(formatter): added support for jazzband's sorl-thumbnail tags
Browse files Browse the repository at this point in the history
closes #714
  • Loading branch information
christopherpickering committed Jul 17, 2023
1 parent 502562e commit 86122dc
Show file tree
Hide file tree
Showing 2 changed files with 46 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 @@ -538,6 +538,7 @@ def __init__(
| raw
| blocktrans(?!late)
| blocktranslate
| thumbnail
| set(?!(?:(?!%}).)*=)
"""
+ self.custom_blocks
Expand Down Expand Up @@ -690,6 +691,7 @@ def __init__(
| raw
| blocktrans(?!late)
| blocktranslate
| thumbnail
| set(?!(?:(?!%}).)*=)
"""
Expand Down Expand Up @@ -743,6 +745,8 @@ def __init__(
| endblocktranslate
| set(?!(?:(?!%}).)*=)
| endset
| thumbnail
| endthumbnail
"""
+ self.custom_blocks
+ r""")
Expand Down
42 changes: 42 additions & 0 deletions tests/test_django/test_thumbnail.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
"""Test jazzband sorl-thumbnail tag.
https://github.com/jazzband/sorl-thumbnail
poetry run pytest tests/test_django/test_thumbnail.py
"""
import pytest

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

test_data = [
pytest.param(
(
'{% thumbnail person.profile_photo "200x200" crop="center" as im %}\n'
' <img src="{{ im.url }}"\n'
' width="{{ im.width }}"\n'
' height="{{ im.height }}"\n'
' class="img-thumbnail"\n'
' alt="{{ person.name }}">\n'
"{% endthumbnail %}\n"
),
(
'{% thumbnail person.profile_photo "200x200" crop="center" as im %}\n'
' <img src="{{ im.url }}"\n'
' width="{{ im.width }}"\n'
' height="{{ im.height }}"\n'
' class="img-thumbnail"\n'
' alt="{{ person.name }}">\n'
"{% endthumbnail %}\n"
),
id="thumbnail",
),
]


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

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

0 comments on commit 86122dc

Please sign in to comment.