22
33from __future__ import annotations
44
5+ from dataclasses import dataclass
56from typing import TYPE_CHECKING
67
78from litestar .plugins import InitPluginProtocol
2425 from litestar .config .app import AppConfig
2526
2627
28+ @dataclass
29+ class HTMXConfig :
30+ """Configuration for HTMX Plugin."""
31+
32+ set_request_class_globally : bool = True
33+ """Sets the `app_config.request_class` to the `HTMXRequest` class at the application level. Defaults to True"""
34+
35+
2736class HTMXPlugin (InitPluginProtocol ):
2837 """HTMX Plugin."""
2938
30- def __init__ (self ) -> None :
31- """Initialize the plugin."""
39+ def __init__ (self , config : HTMXConfig | None = None ) -> None :
40+ """Initialize the plugin.
41+
42+ Args:
43+ config: Configuration for flash messages, including the template engine instance.
44+ """
45+ self ._config = config or HTMXConfig ()
46+
47+ @property
48+ def config (self ) -> HTMXConfig :
49+ return self ._config
3250
3351 def on_app_init (self , app_config : AppConfig ) -> AppConfig :
3452 """Register the HTMX configuration.
@@ -39,7 +57,7 @@ def on_app_init(self, app_config: AppConfig) -> AppConfig:
3957 Returns:
4058 The application configuration with the message callable registered.
4159 """
42- if app_config .request_class is None :
60+ if self . config . set_request_class_globally and app_config .request_class is None :
4361 app_config .request_class = HTMXRequest
4462 app_config .signature_types = [
4563 HTMXRequest ,
0 commit comments