From: Kenneth Dombrowski Date: Sat, 11 May 2013 21:30:43 +0000 (-0400) Subject: * create config option for optional jinja2 extensions X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=155d234d95a6bdbbdc546d9919b692a95e7a5c9b;p=mediagoblin.git * create config option for optional jinja2 extensions * add comments & clarify code for jinja2 extensions Conflicts: mediagoblin/config_spec.ini --- diff --git a/mediagoblin/config_spec.ini b/mediagoblin/config_spec.ini index edbebd85..81dadd25 100644 --- a/mediagoblin/config_spec.ini +++ b/mediagoblin/config_spec.ini @@ -75,6 +75,12 @@ theme = string() plugin_web_path = string(default="/plugin_static/") plugin_linked_assets_dir = string(default="%(here)s/user_dev/plugin_static/") +[jinja2] +# Jinja2 supports more directives than the minimum required by mediagoblin. +# This setting allows users creating custom templates to specify a list of +# additional extensions they want to use. example value: +# extensions = jinja2.ext.loopcontrols , jinja2.ext.with_ +extensions = string_list(default=list()) [storage:publicstore] storage_class = string(default="mediagoblin.storage.filestorage:BasicFileStorage") diff --git a/mediagoblin/tools/template.py b/mediagoblin/tools/template.py index 615ce129..4c634ea2 100644 --- a/mediagoblin/tools/template.py +++ b/mediagoblin/tools/template.py @@ -50,6 +50,12 @@ def get_jinja_env(template_loader, locale): if locale in SETUP_JINJA_ENVS: return SETUP_JINJA_ENVS[locale] + # The default config does not require a [jinja2] block. + # You may create one if you wish to enable additional jinja2 extensions, + # see example in config_spec.ini + jinja2_config = mg_globals.global_config.get('jinja2', {}) + local_exts = jinja2_config.get('extensions', []) + # jinja2.StrictUndefined will give exceptions on references # to undefined/unknown variables in templates. template_env = jinja2.Environment( @@ -57,7 +63,7 @@ def get_jinja_env(template_loader, locale): undefined=jinja2.StrictUndefined, extensions=[ 'jinja2.ext.i18n', 'jinja2.ext.autoescape', - TemplateHookExtension]) + TemplateHookExtension] + local_exts) template_env.install_gettext_callables( mg_globals.thread_scope.translations.ugettext,