1212 ModuleTemplating ,
1313)
1414from ellar .common .types import ASGIApp
15+ from ellar .core .conf import Config
1516from ellar .core .connection import Request
1617from ellar .core .staticfiles import StaticFiles
18+ from ellar .di import EllarInjector
1719from jinja2 import Environment as BaseEnvironment
1820from starlette .templating import pass_context
1921
20- if t .TYPE_CHECKING : # pragma: no cover
21- from ellar .core .conf import Config
22- from ellar .core .main import App
23- from ellar .di import EllarInjector
22+ if t .TYPE_CHECKING :
23+ from .main import App
2424
2525
26- class AppTemplating (JinjaTemplating ):
27- config : "Config"
26+ class AppMixin (JinjaTemplating ):
2827 _static_app : t .Optional [ASGIApp ]
29- _injector : "EllarInjector"
28+ _injector : EllarInjector
29+ _config : Config
3030 has_static_files : bool
3131
3232 @abstractmethod
@@ -43,12 +43,12 @@ def get_module_loaders(self) -> t.Generator[ModuleTemplating, None, None]:
4343
4444 @property
4545 def debug (self ) -> bool :
46- return self .config .DEBUG
46+ return self ._config .DEBUG
4747
4848 @debug .setter
4949 def debug (self , value : bool ) -> None :
5050 del self .__dict__ ["jinja_environment" ]
51- self .config .DEBUG = value
51+ self ._config .DEBUG = value
5252 # TODO: Add warning
5353 self .rebuild_middleware_stack ()
5454
@@ -70,7 +70,7 @@ def select_jinja_auto_escape(filename: str) -> bool:
7070 "autoescape" : select_jinja_auto_escape ,
7171 }
7272 jinja_options : t .Dict = t .cast (
73- t .Dict , self .config .JINJA_TEMPLATES_OPTIONS or {}
73+ t .Dict , self ._config .JINJA_TEMPLATES_OPTIONS or {}
7474 )
7575
7676 for k , v in options_defaults .items ():
@@ -81,12 +81,12 @@ def url_for(context: dict, name: str, **path_params: t.Any) -> URL:
8181 request = t .cast (Request , context ["request" ])
8282 return request .url_for (name , ** path_params )
8383
84- app : App = t .cast ("App" , self )
84+ app : " App" = t .cast ("App" , self )
8585
8686 jinja_env = Environment (app , ** jinja_options )
8787 jinja_env .globals .update (
8888 url_for = url_for ,
89- config = self .config ,
89+ config = self ._config ,
9090 )
9191 jinja_env .policies ["json.dumps_function" ] = json .dumps
9292 return jinja_env
@@ -97,7 +97,7 @@ def create_global_jinja_loader(self) -> JinjaLoader:
9797 def create_static_app (self ) -> ASGIApp :
9898 return StaticFiles (
9999 directories = self .static_files , # type: ignore[arg-type]
100- packages = self .config .STATIC_FOLDER_PACKAGES ,
100+ packages = self ._config .STATIC_FOLDER_PACKAGES ,
101101 )
102102
103103 def reload_static_app (self ) -> None :
@@ -107,12 +107,12 @@ def reload_static_app(self) -> None:
107107 self ._update_jinja_env_filters (self .jinja_environment )
108108
109109 def _update_jinja_env_filters (self , jinja_environment : BaseEnvironment ) -> None :
110- jinja_environment .globals .update (self .config .get (TEMPLATE_GLOBAL_KEY , {}))
111- jinja_environment .filters .update (self .config .get (TEMPLATE_FILTER_KEY , {}))
110+ jinja_environment .globals .update (self ._config .get (TEMPLATE_GLOBAL_KEY , {}))
111+ jinja_environment .filters .update (self ._config .get (TEMPLATE_FILTER_KEY , {}))
112112
113113 @cached_property
114114 def static_files (self ) -> t .List [str ]:
115- static_directories = t .cast (t .List , self .config .STATIC_DIRECTORIES or [])
115+ static_directories = t .cast (t .List , self ._config .STATIC_DIRECTORIES or [])
116116 for module in self .get_module_loaders ():
117117 if module .static_directory :
118118 static_directories .append (module .static_directory )
0 commit comments