mirror of
https://github.com/django-components/django-components.git
synced 2025-11-21 15:13:41 +00:00
Partial implementation fill-tags plus update tests
Implement {% fill %} tags. Next: update tests.
Bring back support for {%slot%} blocks for bckwrd-compat and implement ambig. resolution policy
Update tests to use fill blocks. Add extra checks that raise errors
Add new tests for fill-slot nesting
Update README. Editing still required
remove unused var ctxt after flake8 complaint
fix flake8 warning about slotless f-string
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
Add new slot aliases in fill context. Clean up rendering logic in Component. Update docs.
fix flake8, isort, black errors
Refactor duplicated name validation
Add if_filled tag + elif_filled...else_filled...endif_filled for cond. slots
Fix mistake in do_if_filled() docstring
Upload templates for tests! D'oh
Incorporate PR feedback
Drop Literal type hint; Use isort off-on instead of skip in tests
Treat all fill,slot,if_filled,component names as variables
Reset sampleproject components
Add test for variable filled name
Update examples in docs
42 lines
1.2 KiB
Python
42 lines
1.2 KiB
Python
import glob
|
|
import importlib
|
|
import importlib.util
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
import django
|
|
from django.template.engine import Engine
|
|
from django.utils.module_loading import autodiscover_modules
|
|
|
|
from django_components.template_loader import Loader
|
|
|
|
if django.VERSION < (3, 2):
|
|
default_app_config = "django_components.apps.ComponentsConfig"
|
|
|
|
|
|
def autodiscover():
|
|
from django_components.app_settings import app_settings
|
|
|
|
if app_settings.AUTODISCOVER:
|
|
# Autodetect a components.py file in each app directory
|
|
autodiscover_modules("components")
|
|
|
|
# Autodetect a <component>.py file in a components dir
|
|
current_engine = Engine.get_default()
|
|
loader = Loader(current_engine)
|
|
dirs = loader.get_dirs()
|
|
for directory in dirs:
|
|
for path in glob.iglob(str(directory / "**/*.py"), recursive=True):
|
|
import_file(path)
|
|
|
|
for path in app_settings.LIBRARIES:
|
|
importlib.import_module(path)
|
|
|
|
|
|
def import_file(path):
|
|
MODULE_PATH = path
|
|
MODULE_NAME = Path(path).stem
|
|
spec = importlib.util.spec_from_file_location(MODULE_NAME, MODULE_PATH)
|
|
module = importlib.util.module_from_spec(spec)
|
|
sys.modules[spec.name] = module
|
|
spec.loader.exec_module(module)
|