Mercurial > hg
comparison mercurial/formatter.py @ 32833:99df35499cae
formatter: inline gettemplater()
Since it's highly use-case dependent how template should be looked up,
gettemplater() function isn't useful. Keeping it would introduce another
bug I've made and fixed earlier in this series.
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Sat, 22 Apr 2017 15:11:53 +0900 |
parents | 11e667a8fcba |
children | 9d76812f9b0b |
comparison
equal
deleted
inserted
replaced
32832:11e667a8fcba | 32833:99df35499cae |
---|---|
345 class templateformatter(baseformatter): | 345 class templateformatter(baseformatter): |
346 def __init__(self, ui, out, topic, opts): | 346 def __init__(self, ui, out, topic, opts): |
347 baseformatter.__init__(self, ui, topic, opts, _templateconverter) | 347 baseformatter.__init__(self, ui, topic, opts, _templateconverter) |
348 self._out = out | 348 self._out = out |
349 self._topic = topic | 349 self._topic = topic |
350 self._t = gettemplater(ui, topic, opts.get('template', ''), | 350 spec = lookuptemplate(ui, topic, opts.get('template', '')) |
351 cache=templatekw.defaulttempl) | 351 self._t = loadtemplater(ui, topic, spec, cache=templatekw.defaulttempl) |
352 self._counter = itertools.count() | 352 self._counter = itertools.count() |
353 self._cache = {} # for templatekw/funcs to store reusable data | 353 self._cache = {} # for templatekw/funcs to store reusable data |
354 def context(self, **ctxs): | 354 def context(self, **ctxs): |
355 '''insert context objects to be used to render template keywords''' | 355 '''insert context objects to be used to render template keywords''' |
356 assert all(k == 'ctx' for k in ctxs) | 356 assert all(k == 'ctx' for k in ctxs) |
403 tmpl = f.read() | 403 tmpl = f.read() |
404 return tmpl, None | 404 return tmpl, None |
405 | 405 |
406 # constant string? | 406 # constant string? |
407 return tmpl, None | 407 return tmpl, None |
408 | |
409 def gettemplater(ui, topic, spec, cache=None): | |
410 tmpl, mapfile = lookuptemplate(ui, topic, spec) | |
411 return loadtemplater(ui, topic, (tmpl, mapfile), cache=cache) | |
412 | 408 |
413 def loadtemplater(ui, topic, spec, cache=None): | 409 def loadtemplater(ui, topic, spec, cache=None): |
414 """Create a templater from either a literal template or loading from | 410 """Create a templater from either a literal template or loading from |
415 a map file""" | 411 a map file""" |
416 tmpl, mapfile = spec | 412 tmpl, mapfile = spec |