Pillar extensions can now register global Jinja2 context processors.
This commit is contained in:
@@ -304,6 +304,14 @@ class PillarServer(Eve):
|
|||||||
|
|
||||||
pillar.web.jinja.setup_jinja_env(self.jinja_env)
|
pillar.web.jinja.setup_jinja_env(self.jinja_env)
|
||||||
|
|
||||||
|
# Register context processors from extensions
|
||||||
|
for ext in self.pillar_extensions.values():
|
||||||
|
if not ext.has_context_processor:
|
||||||
|
continue
|
||||||
|
|
||||||
|
self.log.debug('Registering context processor for %s', ext.name)
|
||||||
|
self.context_processor(ext.context_processor)
|
||||||
|
|
||||||
def _config_static_dirs(self):
|
def _config_static_dirs(self):
|
||||||
# Setup static folder for the instanced app
|
# Setup static folder for the instanced app
|
||||||
self.static_folder = os.path.join(self.app_root, 'static')
|
self.static_folder = os.path.join(self.app_root, 'static')
|
||||||
|
@@ -26,6 +26,9 @@ class PillarExtension(object, metaclass=abc.ABCMeta):
|
|||||||
# Set to True when your extension implements the project_settings() method.
|
# Set to True when your extension implements the project_settings() method.
|
||||||
has_project_settings = False
|
has_project_settings = False
|
||||||
|
|
||||||
|
# Set to True when your extension implements the context_processor() method.
|
||||||
|
has_context_processor = False
|
||||||
|
|
||||||
# List of Celery task modules introduced by this extension.
|
# List of Celery task modules introduced by this extension.
|
||||||
celery_task_modules: typing.List[str] = []
|
celery_task_modules: typing.List[str] = []
|
||||||
|
|
||||||
@@ -121,3 +124,11 @@ class PillarExtension(object, metaclass=abc.ABCMeta):
|
|||||||
:param template_args: additional template arguments.
|
:param template_args: additional template arguments.
|
||||||
:returns: a Flask HTTP response
|
:returns: a Flask HTTP response
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
def context_processor(self) -> dict:
|
||||||
|
"""Returns a dictionary that gets injected into the Flask Jinja2 namespace.
|
||||||
|
|
||||||
|
Set has_context_processor to True when your extension implements this method.
|
||||||
|
"""
|
||||||
|
|
||||||
|
return {}
|
||||||
|
Reference in New Issue
Block a user