Skip to content

Commit

Permalink
Warn the user when the template name does not match the comopnent name
Browse files Browse the repository at this point in the history
  • Loading branch information
edelvalle committed Aug 22, 2024
1 parent 0e4446b commit 246e649
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/djhtmx/component.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from dataclasses import dataclass, field as dataclass_field
from functools import cached_property
from itertools import chain
from os.path import basename
from urllib.parse import urlparse
from uuid import uuid4

Expand All @@ -22,6 +23,7 @@
from django.utils.html import format_html
from django.utils.safestring import SafeString, mark_safe
from pydantic import BaseModel, ConfigDict, Field, validate_call
from pydantic.fields import ModelPrivateAttr
from typing_extensions import deprecated

from . import json
Expand Down Expand Up @@ -546,6 +548,16 @@ def __init_subclass__(cls, public=None):
FQN[cls],
)

assert isinstance(cls._template_name, ModelPrivateAttr)
if (
isinstance(cls._template_name.default, str)
and basename(cls._template_name.default) != f"{component_name}.html"
):
logger.warn(
"HTMX Component <%s> template name does not match the component name",
FQN[cls],
)

# We use 'get_type_hints' to resolve the forward refs if needed, but
# we only need to rewrite the actual annotations of the current class,
# that's why we iter over the '__annotations__' names.
Expand Down

0 comments on commit 246e649

Please sign in to comment.