Show More
@@ -350,8 +350,12 b' class templateformatter(baseformatter):' | |||
|
350 | 350 | spec = lookuptemplate(ui, topic, opts.get('template', '')) |
|
351 | 351 | self._tref = spec.ref |
|
352 | 352 | self._t = loadtemplater(ui, spec, cache=templatekw.defaulttempl) |
|
353 | self._parts = templatepartsmap(spec, self._t, | |
|
354 | ['docheader', 'docfooter']) | |
|
353 | 355 | self._counter = itertools.count() |
|
354 | 356 | self._cache = {} # for templatekw/funcs to store reusable data |
|
357 | self._renderitem('docheader', {}) | |
|
358 | ||
|
355 | 359 | def context(self, **ctxs): |
|
356 | 360 | '''insert context objects to be used to render template keywords''' |
|
357 | 361 | ctxs = pycompat.byteskwargs(ctxs) |
@@ -363,7 +367,11 b' class templateformatter(baseformatter):' | |||
|
363 | 367 | item['index'] = next(self._counter) |
|
364 | 368 | self._renderitem(self._tref, item) |
|
365 | 369 | |
|
366 |
def _renderitem(self, |
|
|
370 | def _renderitem(self, part, item): | |
|
371 | if part not in self._parts: | |
|
372 | return | |
|
373 | ref = self._parts[part] | |
|
374 | ||
|
367 | 375 | # TODO: add support for filectx. probably each template keyword or |
|
368 | 376 | # function will have to declare dependent resources. e.g. |
|
369 | 377 | # @templatekeyword(..., requires=('ctx',)) |
@@ -381,6 +389,10 b' class templateformatter(baseformatter):' | |||
|
381 | 389 | g = self._t(ref, ui=self._ui, cache=self._cache, **props) |
|
382 | 390 | self._out.write(templater.stringify(g)) |
|
383 | 391 | |
|
392 | def end(self): | |
|
393 | baseformatter.end(self) | |
|
394 | self._renderitem('docfooter', {}) | |
|
395 | ||
|
384 | 396 | templatespec = collections.namedtuple(r'templatespec', |
|
385 | 397 | r'ref tmpl mapfile') |
|
386 | 398 | |
@@ -434,6 +446,13 b' def lookuptemplate(ui, topic, tmpl):' | |||
|
434 | 446 | # constant string? |
|
435 | 447 | return templatespec('', tmpl, None) |
|
436 | 448 | |
|
449 | def templatepartsmap(spec, t, partnames): | |
|
450 | """Create a mapping of {part: ref}""" | |
|
451 | partsmap = {spec.ref: spec.ref} # initial ref must exist in t | |
|
452 | if spec.mapfile: | |
|
453 | partsmap.update((p, p) for p in partnames if p in t) | |
|
454 | return partsmap | |
|
455 | ||
|
437 | 456 | def loadtemplater(ui, spec, cache=None): |
|
438 | 457 | """Create a templater from either a literal template or loading from |
|
439 | 458 | a map file""" |
@@ -530,6 +530,19 b' template output:' | |||
|
530 | 530 | a: Adding b branch head 2 |
|
531 | 531 | default: Adding root node |
|
532 | 532 | |
|
533 | $ cat <<'EOF' > "$TESTTMP/map-myjson" | |
|
534 | > docheader = '\{\n' | |
|
535 | > docfooter = '\n}\n' | |
|
536 | > branches = '{ifeq(index, 0, "", ",\n")} {dict(branch, node|short)|json}' | |
|
537 | > EOF | |
|
538 | $ hg branches -T "$TESTTMP/map-myjson" | |
|
539 | { | |
|
540 | {"branch": "b", "node": "e23b5505d1ad"}, | |
|
541 | {"branch": "a branch *", "node": "10ff5895aa57"}, (glob) | |
|
542 | {"branch": "a", "node": "d8cbc61dbaa6"}, | |
|
543 | {"branch": "default", "node": "19709c5a4e75"} | |
|
544 | } | |
|
545 | ||
|
533 | 546 | Tests of revision branch name caching |
|
534 | 547 | |
|
535 | 548 | We rev branch cache is updated automatically. In these tests we use a trick to |
General Comments 0
You need to be logged in to leave comments.
Login now