summaryrefslogtreecommitdiff
path: root/sphinx/jinja2glue.py
diff options
context:
space:
mode:
Diffstat (limited to 'sphinx/jinja2glue.py')
-rw-r--r--sphinx/jinja2glue.py19
1 files changed, 16 insertions, 3 deletions
diff --git a/sphinx/jinja2glue.py b/sphinx/jinja2glue.py
index cc935d577..f19454c27 100644
--- a/sphinx/jinja2glue.py
+++ b/sphinx/jinja2glue.py
@@ -20,11 +20,12 @@ 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:
# For type annotation
- from typing import Any, Callable, Dict, List, Iterator, Tuple # NOQA
+ from typing import Any, Callable, Dict, List, Iterator, Tuple, Union # NOQA
from jinja2.environment import Environment # NOQA
from sphinx.builders import Builder # NOQA
from sphinx.theming import Theme # NOQA
@@ -46,7 +47,7 @@ def _toint(val):
def _todim(val):
- # type (int or unicode) -> unicode
+ # type: (Union[int, unicode]) -> unicode
"""
Make val a css dimension. In particular the following transformations
are performed:
@@ -61,7 +62,7 @@ def _todim(val):
return 'initial'
elif str(val).isdigit():
return '0' if int(val) == 0 else '%spx' % val
- return val
+ return val # type: ignore
def _slice_index(values, slices):
@@ -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: