Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Allow no template_config, enabling you to use litestar-vite with html frameworks other than Jinja2 #63

Merged
merged 2 commits into from
Dec 29, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 9 additions & 15 deletions src/py/litestar_vite/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand Down Expand Up @@ -128,20 +127,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
Loading