From fd0f5780f8e89923a0086c18970004475c1fcbc7 Mon Sep 17 00:00:00 2001 From: CJ Lazell Date: Mon, 23 Dec 2024 11:48:06 -0600 Subject: [PATCH 1/2] Allow no template_config Allowing no template_config enables you to use litestar-vite on html frameworks other than `Jinja2`. --- src/py/litestar_vite/plugin.py | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/src/py/litestar_vite/plugin.py b/src/py/litestar_vite/plugin.py index 9e71f72..1b55513 100644 --- a/src/py/litestar_vite/plugin.py +++ b/src/py/litestar_vite/plugin.py @@ -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: From bd184b4666bf2bcc7eeea67caaa52f074cd497fb Mon Sep 17 00:00:00 2001 From: CJ Lazell Date: Mon, 23 Dec 2024 11:52:48 -0600 Subject: [PATCH 2/2] refactor: Remove unused import of ImproperlyConfiguredException --- src/py/litestar_vite/plugin.py | 1 - 1 file changed, 1 deletion(-) diff --git a/src/py/litestar_vite/plugin.py b/src/py/litestar_vite/plugin.py index 1b55513..c96193a 100644 --- a/src/py/litestar_vite/plugin.py +++ b/src/py/litestar_vite/plugin.py @@ -11,7 +11,6 @@ from litestar.cli._utils import console from litestar.contrib.jinja import JinjaTemplateEngine -from litestar.exceptions import ImproperlyConfiguredException from litestar.plugins import CLIPlugin, InitPluginProtocol from litestar.static_files import create_static_files_router # pyright: ignore[reportUnknownVariableType]