Skip to content

Commit

Permalink
Allow no template_config
Browse files Browse the repository at this point in the history
Allowing no template_config enables you to use litestar-vite on html frameworks other than `Jinja2`.
  • Loading branch information
cj committed Dec 23, 2024
1 parent af703e4 commit fd0f578
Showing 1 changed file with 9 additions and 14 deletions.
23 changes: 9 additions & 14 deletions src/py/litestar_vite/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,20 +128,15 @@ def on_app_init(self, app_config: AppConfig) -> AppConfig:
"""
from litestar_vite.loader import render_asset_tag, render_hmr_client

if app_config.template_config is None: # pyright: ignore[reportUnknownMemberType]
msg = "A template configuration is required for Vite."
raise ImproperlyConfiguredException(msg)
if not isinstance(app_config.template_config.engine_instance, JinjaTemplateEngine): # pyright: ignore[reportUnknownMemberType]
msg = "Jinja2 template engine is required for Vite."
raise ImproperlyConfiguredException(msg)
app_config.template_config.engine_instance.register_template_callable( # pyright: ignore[reportUnknownMemberType]
key="vite_hmr",
template_callable=render_hmr_client,
)
app_config.template_config.engine_instance.register_template_callable( # pyright: ignore[reportUnknownMemberType]
key="vite",
template_callable=render_asset_tag,
)
if app_config.template_config and isinstance(app_config.template_config.engine_instance, JinjaTemplateEngine): # pyright: ignore[reportUnknownMemberType]
app_config.template_config.engine_instance.register_template_callable( # pyright: ignore[reportUnknownMemberType]
key="vite_hmr",
template_callable=render_hmr_client,
)
app_config.template_config.engine_instance.register_template_callable( # pyright: ignore[reportUnknownMemberType]
key="vite",
template_callable=render_asset_tag,
)
if self._config.set_static_folders:
static_dirs = [Path(self._config.bundle_dir), Path(self._config.resource_dir)]
if Path(self._config.public_dir).exists() and self._config.public_dir != self._config.bundle_dir:
Expand Down

0 comments on commit fd0f578

Please sign in to comment.