##// END OF EJS Templates
formatter: proxy fm.context() through converter...
Yuya Nishihara -
r33090:04b3743c default
parent child Browse files
Show More
@@ -127,6 +127,10 b' pickle = util.pickle'
127 127
128 128 class _nullconverter(object):
129 129 '''convert non-primitive data types to be processed by formatter'''
130
131 # set to True if context object should be stored as item
132 storecontext = False
133
130 134 @staticmethod
131 135 def formatdate(date, fmt):
132 136 '''convert date tuple to appropriate format'''
@@ -178,7 +182,10 b' class baseformatter(object):'
178 182 return self._converter.formatlist(data, name, fmt, sep)
179 183 def context(self, **ctxs):
180 184 '''insert context objects to be used to render template keywords'''
181 pass
185 ctxs = pycompat.byteskwargs(ctxs)
186 assert all(k == 'ctx' for k in ctxs)
187 if self._converter.storecontext:
188 self._item.update(ctxs)
182 189 def data(self, **data):
183 190 '''insert data into item that's not shown in default output'''
184 191 data = pycompat.byteskwargs(data)
@@ -228,6 +235,9 b' def _iteritems(data):'
228 235
229 236 class _plainconverter(object):
230 237 '''convert non-primitive data types to text'''
238
239 storecontext = False
240
231 241 @staticmethod
232 242 def formatdate(date, fmt):
233 243 '''stringify date tuple in the given format'''
@@ -323,6 +333,9 b' class jsonformatter(baseformatter):'
323 333
324 334 class _templateconverter(object):
325 335 '''convert non-primitive data types to be processed by templater'''
336
337 storecontext = True
338
326 339 @staticmethod
327 340 def formatdate(date, fmt):
328 341 '''return date tuple'''
@@ -356,12 +369,6 b' class templateformatter(baseformatter):'
356 369 self._cache = {} # for templatekw/funcs to store reusable data
357 370 self._renderitem('docheader', {})
358 371
359 def context(self, **ctxs):
360 '''insert context objects to be used to render template keywords'''
361 ctxs = pycompat.byteskwargs(ctxs)
362 assert all(k == 'ctx' for k in ctxs)
363 self._item.update(ctxs)
364
365 372 def _showitem(self):
366 373 item = self._item.copy()
367 374 item['index'] = index = next(self._counter)
General Comments 0
You need to be logged in to leave comments. Login now