template: add support for UI templates
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
This commit is contained in:
parent
b7768671aa
commit
c24fd7d11c
|
@ -25,12 +25,16 @@ class TemplateFactory:
|
||||||
self.server = config.get_server()
|
self.server = config.get_server()
|
||||||
secrets: Secrets = self.server.load_component(config, 'secrets')
|
secrets: Secrets = self.server.load_component(config, 'secrets')
|
||||||
self.jenv = jinja2.Environment('{%', '%}', '{', '}')
|
self.jenv = jinja2.Environment('{%', '%}', '{', '}')
|
||||||
self.async_env = jinja2.Environment('{%', '%}', '{', '}',
|
self.async_env = jinja2.Environment(
|
||||||
enable_async=True)
|
'{%', '%}', '{', '}', enable_async=True
|
||||||
|
)
|
||||||
|
self.ui_env = jinja2.Environment(enable_async=True)
|
||||||
self.jenv.add_extension("jinja2.ext.do")
|
self.jenv.add_extension("jinja2.ext.do")
|
||||||
self.jenv.filters['fromjson'] = json.loads
|
self.jenv.filters['fromjson'] = json.loads
|
||||||
self.async_env.add_extension("jinja2.ext.do")
|
self.async_env.add_extension("jinja2.ext.do")
|
||||||
self.async_env.filters['fromjson'] = json.loads
|
self.async_env.filters['fromjson'] = json.loads
|
||||||
|
self.ui_env.add_extension("jinja2.ext.do")
|
||||||
|
self.ui_env.filters['fromjson'] = json.loads
|
||||||
self.add_environment_global('raise_error', self._raise_error)
|
self.add_environment_global('raise_error', self._raise_error)
|
||||||
self.add_environment_global('secrets', secrets)
|
self.add_environment_global('secrets', secrets)
|
||||||
|
|
||||||
|
@ -56,6 +60,14 @@ class TemplateFactory:
|
||||||
raise
|
raise
|
||||||
return JinjaTemplate(source, self.server, template, is_async)
|
return JinjaTemplate(source, self.server, template, is_async)
|
||||||
|
|
||||||
|
def create_ui_template(self, source: str) -> JinjaTemplate:
|
||||||
|
try:
|
||||||
|
template = self.ui_env.from_string(source)
|
||||||
|
except Exception:
|
||||||
|
logging.exception(f"Error creating template from source:\n{source}")
|
||||||
|
raise
|
||||||
|
return JinjaTemplate(source, self.server, template, True)
|
||||||
|
|
||||||
|
|
||||||
class JinjaTemplate:
|
class JinjaTemplate:
|
||||||
def __init__(self,
|
def __init__(self,
|
||||||
|
|
Loading…
Reference in New Issue