formatter: proxy fm.context() through converter
Otherwise nested template formatter would not see the context objects.
It's just a boolean flag now. We might want to change it to 'ctxs -> items'
function so changectx attributes are populated automatically in JSON, but
I'm not sure.
--- a/mercurial/formatter.py Mon Jun 26 09:18:55 2017 +0900
+++ b/mercurial/formatter.py Mon Jun 26 09:33:01 2017 +0900
@@ -127,6 +127,10 @@
class _nullconverter(object):
'''convert non-primitive data types to be processed by formatter'''
+
+ # set to True if context object should be stored as item
+ storecontext = False
+
@staticmethod
def formatdate(date, fmt):
'''convert date tuple to appropriate format'''
@@ -178,7 +182,10 @@
return self._converter.formatlist(data, name, fmt, sep)
def context(self, **ctxs):
'''insert context objects to be used to render template keywords'''
- pass
+ ctxs = pycompat.byteskwargs(ctxs)
+ assert all(k == 'ctx' for k in ctxs)
+ if self._converter.storecontext:
+ self._item.update(ctxs)
def data(self, **data):
'''insert data into item that's not shown in default output'''
data = pycompat.byteskwargs(data)
@@ -228,6 +235,9 @@
class _plainconverter(object):
'''convert non-primitive data types to text'''
+
+ storecontext = False
+
@staticmethod
def formatdate(date, fmt):
'''stringify date tuple in the given format'''
@@ -323,6 +333,9 @@
class _templateconverter(object):
'''convert non-primitive data types to be processed by templater'''
+
+ storecontext = True
+
@staticmethod
def formatdate(date, fmt):
'''return date tuple'''
@@ -356,12 +369,6 @@
self._cache = {} # for templatekw/funcs to store reusable data
self._renderitem('docheader', {})
- def context(self, **ctxs):
- '''insert context objects to be used to render template keywords'''
- ctxs = pycompat.byteskwargs(ctxs)
- assert all(k == 'ctx' for k in ctxs)
- self._item.update(ctxs)
-
def _showitem(self):
item = self._item.copy()
item['index'] = index = next(self._counter)