##// END OF EJS Templates
formatter: provide hint of context keys required by template...
Yuya Nishihara -
r38685:8399438b default
parent child Browse files
Show More
@@ -124,6 +124,7 b' from . import ('
124 error,
124 error,
125 pycompat,
125 pycompat,
126 templatefilters,
126 templatefilters,
127 templatefuncs,
127 templatekw,
128 templatekw,
128 templater,
129 templater,
129 templateutil,
130 templateutil,
@@ -192,6 +193,9 b' class baseformatter(object):'
192 # name is mandatory argument for now, but it could be optional if
193 # name is mandatory argument for now, but it could be optional if
193 # we have default template keyword, e.g. {item}
194 # we have default template keyword, e.g. {item}
194 return self._converter.formatlist(data, name, fmt, sep)
195 return self._converter.formatlist(data, name, fmt, sep)
196 def contexthint(self, datafields):
197 '''set of context object keys to be required given datafields set'''
198 return set()
195 def context(self, **ctxs):
199 def context(self, **ctxs):
196 '''insert context objects to be used to render template keywords'''
200 '''insert context objects to be used to render template keywords'''
197 ctxs = pycompat.byteskwargs(ctxs)
201 ctxs = pycompat.byteskwargs(ctxs)
@@ -418,6 +422,24 b' class templateformatter(baseformatter):'
418 def _symbolsused(self):
422 def _symbolsused(self):
419 return self._t.symbolsuseddefault()
423 return self._t.symbolsuseddefault()
420
424
425 def contexthint(self, datafields):
426 '''set of context object keys to be required by the template, given
427 datafields overridden by immediate values'''
428 requires = set()
429 ksyms, fsyms = self._symbolsused
430 ksyms = ksyms - set(datafields.split()) # exclude immediate fields
431 symtables = [(ksyms, templatekw.keywords),
432 (fsyms, templatefuncs.funcs)]
433 for syms, table in symtables:
434 for k in syms:
435 f = table.get(k)
436 if not f:
437 continue
438 requires.update(getattr(f, '_requires', ()))
439 if 'repo' in requires:
440 requires.add('ctx') # there's no API to pass repo to formatter
441 return requires & {'ctx', 'fctx'}
442
421 def datahint(self):
443 def datahint(self):
422 '''set of field names to be referenced from the template'''
444 '''set of field names to be referenced from the template'''
423 return self._symbolsused[0]
445 return self._symbolsused[0]
General Comments 0
You need to be logged in to leave comments. Login now