Multi-line tag support, watch component files, and cleanup (#624)

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
This commit is contained in:
Juro Oravec 2024-08-28 07:46:48 +02:00 committed by GitHub
parent b26a201138
commit ab059f362d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 217 additions and 50 deletions

View file

@ -1,4 +1,7 @@
from typing import Any, Callable, List
from pathlib import Path
from typing import Any, Callable, List, Sequence, Union
from django.utils.autoreload import autoreload_started
# Global counter to ensure that all IDs generated by `gen_id` WILL be unique
_id = 0
@ -23,3 +26,13 @@ def find_last_index(lst: List, predicate: Callable[[Any], bool]) -> Any:
def is_str_wrapped_in_quotes(s: str) -> bool:
return s.startswith(('"', "'")) and s[0] == s[-1] and len(s) >= 2
# See https://github.com/EmilStenstrom/django-components/issues/586#issue-2472678136
def watch_files_for_autoreload(watch_list: Sequence[Union[str, Path]]) -> None:
def autoreload_hook(sender: Any, *args: Any, **kwargs: Any) -> None:
watch = sender.extra_files.add
for file in watch_list:
watch(Path(file))
autoreload_started.connect(autoreload_hook)