This is an automated email from the ASF dual-hosted git repository. dill0wn pushed a commit to branch dw/8392 in repository https://gitbox.apache.org/repos/asf/allura.git
commit c3ab440f95b54f8e488b27f40027caee4f9337a5 Author: Dillon Walls <[email protected]> AuthorDate: Tue Jul 20 10:34:46 2021 +0000 [#8392] added 'subrender' jinja filter to render text snippets with current jinja context --- Allura/allura/config/app_cfg.py | 1 + Allura/allura/lib/helpers.py | 6 ++++++ Allura/allura/templates/jinja_master/theme_macros.html | 2 +- 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/Allura/allura/config/app_cfg.py b/Allura/allura/config/app_cfg.py index 58f3a75..1df14fe 100644 --- a/Allura/allura/config/app_cfg.py +++ b/Allura/allura/config/app_cfg.py @@ -115,6 +115,7 @@ class AlluraJinjaRenderer(JinjaRenderer): jinja2_env.filters['datetimeformat'] = helpers.datetimeformat jinja2_env.filters['filter'] = lambda s, t=None: list(filter(t and jinja2_env.tests[t], s)) jinja2_env.filters['nl2br'] = helpers.nl2br_jinja_filter + jinja2_env.filters['subrender'] = helpers.subrender_jinja_filter jinja2_env.globals.update({'hasattr': hasattr}) config['tg.app_globals'].jinja2_env = jinja2_env # TG doesn't need this, but we use g.jinja2_env a lot return {'jinja': cls(jinja2_env)} diff --git a/Allura/allura/lib/helpers.py b/Allura/allura/lib/helpers.py index d70f83a..3e6f15d 100644 --- a/Allura/allura/lib/helpers.py +++ b/Allura/allura/lib/helpers.py @@ -23,6 +23,7 @@ import sys import os import os.path import difflib +import jinja2 import six.moves.urllib.request import six.moves.urllib.parse @@ -797,6 +798,11 @@ def render_any_markup(name, txt, code_mode=False, linenumbers_style=TABLE): txt = '<pre>%s</pre>' % txt return Markup(txt) +@contextfilter +def subrender_jinja_filter(context, value): + _template = context.eval_ctx.environment.from_string(value) + result = _template.render(**context) + return result def nl2br_jinja_filter(value): result = '<br>\n'.join(escape(line) for line in value.split('\n')) diff --git a/Allura/allura/templates/jinja_master/theme_macros.html b/Allura/allura/templates/jinja_master/theme_macros.html index 47b632d..a79f09e 100644 --- a/Allura/allura/templates/jinja_master/theme_macros.html +++ b/Allura/allura/templates/jinja_master/theme_macros.html @@ -174,7 +174,7 @@ http://stackoverflow.com/questions/26582731/redefining-imported-jinja-macros {% if note %} <div id="site-notification"> <section class="site-message info" data-notification-id="{{note._id}}"> - {{note.content|safe}} + {{ note.content|subrender|safe }} <a href="" class="btn btn-close">Close</a> </section> </div>
