diff options
author | Takeshi KOMIYA <i.tkomiya@gmail.com> | 2018-03-18 16:29:46 +0300 |
---|---|---|
committer | Takeshi KOMIYA <i.tkomiya@gmail.com> | 2018-03-18 18:18:10 +0300 |
commit | 52ed9ef3a09e6fa27c1da709303213db512582dd (patch) | |
tree | 55cb11fe88a700101b65e653a4b47b50fea37466 /sphinx/jinja2glue.py | |
parent | bde42595c6f51e9648658840897d25b0827a3cf6 (diff) |
Closes #2157: helper function ``warning()`` for HTML themes is added
Diffstat (limited to 'sphinx/jinja2glue.py')
-rw-r--r-- | sphinx/jinja2glue.py | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/sphinx/jinja2glue.py b/sphinx/jinja2glue.py index 24dd0e0fd..f19454c27 100644 --- a/sphinx/jinja2glue.py +++ b/sphinx/jinja2glue.py @@ -20,6 +20,7 @@ from jinja2.utils import open_if_exists from six import string_types from sphinx.application import TemplateBridge +from sphinx.util import logging from sphinx.util.osutil import mtimes_of_files if False: @@ -113,6 +114,17 @@ class idgen(object): next = __next__ # Python 2/Jinja compatibility +@contextfunction +def warning(context, message, *args, **kwargs): + # type: (Dict, unicode, Any, Any) -> unicode + if 'pagename' in context: + filename = context.get('pagename') + context.get('file_suffix', '') + message = 'in rendering %s: %s' % (filename, message) + logger = logging.getLogger('sphinx.themes') + logger.warning(message, *args, **kwargs) + return '' # return empty string not to output any values + + class SphinxFileSystemLoader(FileSystemLoader): """ FileSystemLoader subclass that is not so strict about '..' entries in @@ -186,6 +198,7 @@ class BuiltinTemplateLoader(TemplateBridge, BaseLoader): self.environment.filters['todim'] = _todim self.environment.filters['slice_index'] = _slice_index self.environment.globals['debug'] = contextfunction(pformat) + self.environment.globals['warning'] = warning self.environment.globals['accesskey'] = contextfunction(accesskey) self.environment.globals['idgen'] = idgen if use_i18n: |