[PATCH 4 of 9] templater: drop 'templ' from resources dict
Yuya Nishihara
yuya at tcha.org
Wed Mar 21 13:51:52 UTC 2018
# HG changeset patch
# User Yuya Nishihara <yuya at tcha.org>
# Date 1521209361 -32400
# Fri Mar 16 23:09:21 2018 +0900
# Node ID fb45cb16834ac9919f7a8b4678fb31ed74d3ffcd
# Parent 38d5aa2f92ff6fabe6242eae313f06860abc5148
templater: drop 'templ' from resources dict
Partially resolves cycle, templ -> context -> templ. This will make it easier
to replace the resources dict with new immutable resource mapper interface.
diff --git a/mercurial/templatekw.py b/mercurial/templatekw.py
--- a/mercurial/templatekw.py
+++ b/mercurial/templatekw.py
@@ -35,19 +35,8 @@ compatdict = templateutil.compatdict
compatlist = templateutil.compatlist
_showcompatlist = templateutil._showcompatlist
-# TODO: temporary hack for porting; will be removed soon
-class _fakecontextwrapper(object):
- def __init__(self, templ):
- self._templ = templ
-
- def preload(self, t):
- return t in self._templ
-
- def process(self, t, mapping):
- return self._templ.generatenamed(t, mapping)
-
def _showlist(name, values, templ, mapping, plural=None, separator=' '):
- context = _fakecontextwrapper(templ)
+ context = templ # this is actually a template context, not a templater
return _showcompatlist(context, mapping, name, values, plural, separator)
def showdict(name, data, mapping, plural=None, key='key', value='value',
diff --git a/mercurial/templater.py b/mercurial/templater.py
--- a/mercurial/templater.py
+++ b/mercurial/templater.py
@@ -738,8 +738,7 @@ class templater(object):
self.filters = templatefilters.filters.copy()
self.filters.update(filters)
self.defaults = defaults
- self._resources = {'templ': lambda context, mapping, key: self}
- self._resources.update(resources)
+ self._resources = resources
self._aliases = aliases
self.minchunk, self.maxchunk = minchunk, maxchunk
self.ecache = {}
diff --git a/mercurial/templateutil.py b/mercurial/templateutil.py
--- a/mercurial/templateutil.py
+++ b/mercurial/templateutil.py
@@ -348,8 +348,11 @@ def runsymbol(context, mapping, key, def
v = default
if callable(v) and getattr(v, '_requires', None) is None:
# old templatekw: expand all keywords and resources
+ # (TODO: deprecate this after porting web template keywords to new API)
props = {k: f(context, mapping, k)
for k, f in context._resources.items()}
+ # pass context to _showcompatlist() through templatekw._showlist()
+ props['templ'] = context
props.update(mapping)
return v(**pycompat.strkwargs(props))
if callable(v):
More information about the Mercurial-devel
mailing list