Show More
@@ -127,6 +127,10 b' pickle = util.pickle' | |||||
127 |
|
127 | |||
128 | class _nullconverter(object): |
|
128 | class _nullconverter(object): | |
129 | '''convert non-primitive data types to be processed by formatter''' |
|
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 | @staticmethod |
|
134 | @staticmethod | |
131 | def formatdate(date, fmt): |
|
135 | def formatdate(date, fmt): | |
132 | '''convert date tuple to appropriate format''' |
|
136 | '''convert date tuple to appropriate format''' | |
@@ -178,7 +182,10 b' class baseformatter(object):' | |||||
178 | return self._converter.formatlist(data, name, fmt, sep) |
|
182 | return self._converter.formatlist(data, name, fmt, sep) | |
179 | def context(self, **ctxs): |
|
183 | def context(self, **ctxs): | |
180 | '''insert context objects to be used to render template keywords''' |
|
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 | def data(self, **data): |
|
189 | def data(self, **data): | |
183 | '''insert data into item that's not shown in default output''' |
|
190 | '''insert data into item that's not shown in default output''' | |
184 | data = pycompat.byteskwargs(data) |
|
191 | data = pycompat.byteskwargs(data) | |
@@ -228,6 +235,9 b' def _iteritems(data):' | |||||
228 |
|
235 | |||
229 | class _plainconverter(object): |
|
236 | class _plainconverter(object): | |
230 | '''convert non-primitive data types to text''' |
|
237 | '''convert non-primitive data types to text''' | |
|
238 | ||||
|
239 | storecontext = False | |||
|
240 | ||||
231 | @staticmethod |
|
241 | @staticmethod | |
232 | def formatdate(date, fmt): |
|
242 | def formatdate(date, fmt): | |
233 | '''stringify date tuple in the given format''' |
|
243 | '''stringify date tuple in the given format''' | |
@@ -323,6 +333,9 b' class jsonformatter(baseformatter):' | |||||
323 |
|
333 | |||
324 | class _templateconverter(object): |
|
334 | class _templateconverter(object): | |
325 | '''convert non-primitive data types to be processed by templater''' |
|
335 | '''convert non-primitive data types to be processed by templater''' | |
|
336 | ||||
|
337 | storecontext = True | |||
|
338 | ||||
326 | @staticmethod |
|
339 | @staticmethod | |
327 | def formatdate(date, fmt): |
|
340 | def formatdate(date, fmt): | |
328 | '''return date tuple''' |
|
341 | '''return date tuple''' | |
@@ -356,12 +369,6 b' class templateformatter(baseformatter):' | |||||
356 | self._cache = {} # for templatekw/funcs to store reusable data |
|
369 | self._cache = {} # for templatekw/funcs to store reusable data | |
357 | self._renderitem('docheader', {}) |
|
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 | def _showitem(self): |
|
372 | def _showitem(self): | |
366 | item = self._item.copy() |
|
373 | item = self._item.copy() | |
367 | item['index'] = index = next(self._counter) |
|
374 | item['index'] = index = next(self._counter) |
General Comments 0
You need to be logged in to leave comments.
Login now