|
@@ -18,23 +18,29 @@ from flaskbb.utils.datastructures import TemplateEventResult
|
|
from flaskbb.plugins.models import PluginRegistry
|
|
from flaskbb.plugins.models import PluginRegistry
|
|
|
|
|
|
|
|
|
|
-def template_hook(name, silent=True, **kwargs):
|
|
|
|
|
|
+def template_hook(name, silent=True, is_markup=True, **kwargs):
|
|
"""Calls the given template hook.
|
|
"""Calls the given template hook.
|
|
|
|
|
|
:param name: The name of the hook.
|
|
:param name: The name of the hook.
|
|
:param silent: If set to ``False``, it will raise an exception if a hook
|
|
:param silent: If set to ``False``, it will raise an exception if a hook
|
|
doesn't exist. Defauls to ``True``.
|
|
doesn't exist. Defauls to ``True``.
|
|
|
|
+ :param is_markup: Determines if the hook should return a Markup object or not.
|
|
|
|
+ Setting to False returns a TemplateEventResult object. The
|
|
|
|
+ default is True.
|
|
:param kwargs: Additional kwargs that should be passed to the hook.
|
|
:param kwargs: Additional kwargs that should be passed to the hook.
|
|
"""
|
|
"""
|
|
try:
|
|
try:
|
|
hook = getattr(current_app.pluggy.hook, name)
|
|
hook = getattr(current_app.pluggy.hook, name)
|
|
- result = hook(**kwargs)
|
|
|
|
|
|
+ result = TemplateEventResult(hook(**kwargs))
|
|
except AttributeError: # raised if hook doesn't exist
|
|
except AttributeError: # raised if hook doesn't exist
|
|
if silent:
|
|
if silent:
|
|
return ""
|
|
return ""
|
|
raise
|
|
raise
|
|
|
|
|
|
- return Markup(TemplateEventResult(result))
|
|
|
|
|
|
+ if is_markup:
|
|
|
|
+ return Markup(result)
|
|
|
|
+
|
|
|
|
+ return result
|
|
|
|
|
|
|
|
|
|
def validate_plugin(name):
|
|
def validate_plugin(name):
|