390 props.update(templatekw.keywords) |
390 props.update(templatekw.keywords) |
391 # explicitly-defined fields precede templatekw |
391 # explicitly-defined fields precede templatekw |
392 props.update(item) |
392 props.update(item) |
393 if 'ctx' in item: |
393 if 'ctx' in item: |
394 # but template resources must be always available |
394 # but template resources must be always available |
395 props['templ'] = self._t |
|
396 props['repo'] = props['ctx'].repo() |
395 props['repo'] = props['ctx'].repo() |
397 props['revcache'] = {} |
396 props['revcache'] = {} |
398 props = pycompat.strkwargs(props) |
397 props = pycompat.strkwargs(props) |
399 g = self._t(ref, ui=self._ui, cache=self._cache, **props) |
398 g = self._t(ref, ui=self._ui, cache=self._cache, **props) |
400 self._out.write(templater.stringify(g)) |
399 self._out.write(templater.stringify(g)) |
466 ref = '%s:%s' % (spec.ref, part) # select config sub-section |
465 ref = '%s:%s' % (spec.ref, part) # select config sub-section |
467 if ref in t: |
466 if ref in t: |
468 partsmap[part] = ref |
467 partsmap[part] = ref |
469 return partsmap |
468 return partsmap |
470 |
469 |
471 def loadtemplater(ui, spec, cache=None): |
470 def loadtemplater(ui, spec, resources=None, cache=None): |
472 """Create a templater from either a literal template or loading from |
471 """Create a templater from either a literal template or loading from |
473 a map file""" |
472 a map file""" |
474 assert not (spec.tmpl and spec.mapfile) |
473 assert not (spec.tmpl and spec.mapfile) |
475 if spec.mapfile: |
474 if spec.mapfile: |
476 return templater.templater.frommapfile(spec.mapfile, cache=cache) |
475 frommapfile = templater.templater.frommapfile |
477 return maketemplater(ui, spec.tmpl, cache=cache) |
476 return frommapfile(spec.mapfile, resources=resources, cache=cache) |
478 |
477 return maketemplater(ui, spec.tmpl, resources=resources, cache=cache) |
479 def maketemplater(ui, tmpl, cache=None): |
478 |
|
479 def maketemplater(ui, tmpl, resources=None, cache=None): |
480 """Create a templater from a string template 'tmpl'""" |
480 """Create a templater from a string template 'tmpl'""" |
481 aliases = ui.configitems('templatealias') |
481 aliases = ui.configitems('templatealias') |
482 t = templater.templater(cache=cache, aliases=aliases) |
482 t = templater.templater(resources=resources, cache=cache, aliases=aliases) |
483 t.cache.update((k, templater.unquotestring(v)) |
483 t.cache.update((k, templater.unquotestring(v)) |
484 for k, v in ui.configitems('templates')) |
484 for k, v in ui.configitems('templates')) |
485 if tmpl: |
485 if tmpl: |
486 t.cache[''] = tmpl |
486 t.cache[''] = tmpl |
487 return t |
487 return t |