Mercurial > public > mercurial-scm > hg
comparison mercurial/formatter.py @ 32873:2ecce24dfcd3
templater: add simple interface for unnamed template (API)
This provides a simpler API for callers which don't need full templating
stack. Instead of storing the given template as the name specified by topic,
use '' as the default template to be rendered.
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Sat, 22 Apr 2017 19:56:47 +0900 |
parents | 883adaea9e80 |
children | c8f2cf18b82e |
comparison
equal
deleted
inserted
replaced
32872:9fcb6df413c9 | 32873:2ecce24dfcd3 |
---|---|
429 """Create a templater from either a literal template or loading from | 429 """Create a templater from either a literal template or loading from |
430 a map file""" | 430 a map file""" |
431 assert not (spec.tmpl and spec.mapfile) | 431 assert not (spec.tmpl and spec.mapfile) |
432 if spec.mapfile: | 432 if spec.mapfile: |
433 return templater.templater.frommapfile(spec.mapfile, cache=cache) | 433 return templater.templater.frommapfile(spec.mapfile, cache=cache) |
434 return maketemplater(ui, spec.ref, spec.tmpl, cache=cache) | 434 return _maketemplater(ui, spec.ref, spec.tmpl, cache=cache) |
435 | 435 |
436 def maketemplater(ui, topic, tmpl, cache=None): | 436 def maketemplater(ui, tmpl, cache=None): |
437 """Create a templater from a string template 'tmpl'""" | 437 """Create a templater from a string template 'tmpl'""" |
438 return _maketemplater(ui, '', tmpl, cache=cache) | |
439 | |
440 def _maketemplater(ui, topic, tmpl, cache=None): | |
438 aliases = ui.configitems('templatealias') | 441 aliases = ui.configitems('templatealias') |
439 t = templater.templater(cache=cache, aliases=aliases) | 442 t = templater.templater(cache=cache, aliases=aliases) |
440 if tmpl: | 443 if tmpl: |
441 t.cache[topic] = tmpl | 444 t.cache[topic] = tmpl |
442 return t | 445 return t |