Skip to content

Commit 78a284f

Browse files
remove django_bird.compiler.Compiler (#151)
1 parent ec5b741 commit 78a284f

File tree

5 files changed

+2
-103
lines changed

5 files changed

+2
-103
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ and this project attempts to adhere to [Semantic Versioning](https://semver.org/
3838
- Removed the deprecated `ENABLE_BIRD_ID_ATTR` setting.
3939
- Removed automatically discovering templates in `BASE_DIR/templates`. Templates must now be in directories configured in Django's template engine settings or app template directories.
4040
- Removed component scanning functionality from `BirdLoader`.
41+
- Removed `django_bird.compiler.Compiler`.
4142

4243
### Fixed
4344

src/django_bird/compiler.py

Lines changed: 0 additions & 24 deletions
This file was deleted.

src/django_bird/loader.py

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,16 @@
11
from __future__ import annotations
22

3-
import hashlib
4-
import re
5-
6-
from django.core.cache import cache
73
from django.template.base import Origin
84
from django.template.engine import Engine
95
from django.template.loaders.filesystem import Loader as FileSystemLoader
106

117
from ._typing import override
12-
from .compiler import Compiler
13-
from .templatetags.tags.bird import TAG
14-
15-
BIRD_TAG_PATTERN = re.compile(rf"{{%\s*{TAG}\s+([^\s%}}]+)")
168

179

1810
class BirdLoader(FileSystemLoader):
1911
def __init__(self, engine: Engine):
2012
super().__init__(engine)
21-
self.compiler = Compiler()
2213

2314
@override
2415
def get_contents(self, origin: Origin) -> str:
25-
contents = super().get_contents(origin)
26-
27-
if not BIRD_TAG_PATTERN.search(contents):
28-
return contents
29-
30-
cache_key = f"bird_component_{hashlib.md5(contents.encode()).hexdigest()}"
31-
compiled = cache.get(cache_key)
32-
if compiled is None:
33-
compiled = self.compiler.compile(contents)
34-
cache.set(cache_key, compiled, timeout=None)
35-
return compiled
16+
return super().get_contents(origin)

tests/test_compiler.py

Lines changed: 0 additions & 35 deletions
This file was deleted.

tests/test_loader.py

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,30 +5,6 @@
55
from django.template.loader import get_template
66
from django.test import override_settings
77

8-
from django_bird.loader import BIRD_TAG_PATTERN
9-
10-
11-
@pytest.mark.parametrize(
12-
"template_content,expected_matches",
13-
[
14-
("{% bird button %}", ["button"]),
15-
("{% bird alert %}{% bird button %}", ["alert", "button"]),
16-
("{% bird 'button' %}", ["button"]),
17-
('{% bird "button" %}', ["button"]),
18-
("{%bird button%}", ["button"]),
19-
("{% bird button %}", ["button"]),
20-
("{% endbird button %}", []),
21-
("{% birds button %}", []),
22-
("<bird:button>", []),
23-
("{% extends 'base.html' %}{% bird button %}", ["button"]),
24-
],
25-
)
26-
def test_bird_tag_pattern(template_content, expected_matches):
27-
matches = [
28-
m.group(1).strip("'\"") for m in BIRD_TAG_PATTERN.finditer(template_content)
29-
]
30-
assert matches == expected_matches
31-
328

339
@pytest.mark.parametrize(
3410
"template_name",

0 commit comments

Comments
 (0)