3333 'chromeFlags' : []
3434}
3535
36-
3736# Public functions
3837
3938def expose (name_or_function = None ):
@@ -88,9 +87,9 @@ def init(path, allowed_extensions=['.js', '.html', '.txt', '.htm', '.xhtml']):
8887
8988
9089def start (* start_urls , ** kwargs ):
91- global _on_close_callback
92-
90+ global _on_close_callback , _jinja_env , _jinja_templates
9391 block = kwargs .pop ('block' , True )
92+ _jinja_templates = kwargs .pop ('templates' , None )
9493 options = kwargs .pop ('options' , {})
9594 size = kwargs .pop ('size' , None )
9695 position = kwargs .pop ('position' , None )
@@ -110,6 +109,14 @@ def start(*start_urls, **kwargs):
110109 options ['port' ] = sock .getsockname ()[1 ]
111110 sock .close ()
112111
112+ if _jinja_templates != None :
113+ from jinja2 import Environment , FileSystemLoader , select_autoescape
114+ templates_path = os .path .join (root_path , _jinja_templates )
115+ _jinja_env = Environment (loader = FileSystemLoader (templates_path ),
116+ autoescape = select_autoescape (['html' , 'xml' ]))
117+ else :
118+ _jinja_env = None
119+
113120 brw .open (start_urls , options )
114121
115122 def run_lambda ():
@@ -146,13 +153,18 @@ def _eel():
146153
147154@btl .route ('/<path:path>' )
148155def _static (path ):
149- return btl .static_file (path , root = root_path )
150-
156+ if _jinja_env != None :
157+ n = len (_jinja_templates + '/' )
158+ template = _jinja_env .get_template (path [n :])
159+ return template .render ()
160+ else :
161+ return btl .static_file (path , root = root_path )
162+
151163
152164@btl .get ('/eel' , apply = [wbs .websocket ])
153165def _websocket (ws ):
154166 global _websockets
155- global _message_loop_queue
167+ global _message_loop_queue # <- what is this for...?
156168
157169 for js_function in _js_functions :
158170 _import_js_function (js_function )
0 commit comments