Show More
@@ -1844,7 +1844,9 b' class changeset_templater(changeset_prin' | |||
|
1844 | 1844 | |
|
1845 | 1845 | changeset_printer.__init__(self, ui, repo, matchfn, diffopts, buffered) |
|
1846 | 1846 | tres = formatter.templateresources(ui, repo) |
|
1847 |
self.t = formatter.loadtemplater(ui, tmplspec, |
|
|
1847 | self.t = formatter.loadtemplater(ui, tmplspec, | |
|
1848 | defaults=templatekw.keywords, | |
|
1849 | resources=tres, | |
|
1848 | 1850 | cache=templatekw.defaulttempl) |
|
1849 | 1851 | self._counter = itertools.count() |
|
1850 | 1852 | self.cache = tres['cache'] # shared with _graphnodeformatter() |
@@ -1886,7 +1888,6 b' class changeset_templater(changeset_prin' | |||
|
1886 | 1888 | def _show(self, ctx, copies, matchfn, hunksfilterfn, props): |
|
1887 | 1889 | '''show a single changeset or file revision''' |
|
1888 | 1890 | props = props.copy() |
|
1889 | props.update(templatekw.keywords) | |
|
1890 | 1891 | props['ctx'] = ctx |
|
1891 | 1892 | props['index'] = index = next(self._counter) |
|
1892 | 1893 | props['revcache'] = {'copies': copies} |
@@ -2658,12 +2659,10 b' def _graphnodeformatter(ui, displayer):' | |||
|
2658 | 2659 | tres = formatter.templateresources(ui) |
|
2659 | 2660 | if isinstance(displayer, changeset_templater): |
|
2660 | 2661 | tres['cache'] = displayer.cache # reuse cache of slow templates |
|
2661 |
templ = formatter.maketemplater(ui, spec, |
|
|
2662 | props = templatekw.keywords.copy() | |
|
2662 | templ = formatter.maketemplater(ui, spec, defaults=templatekw.keywords, | |
|
2663 | resources=tres) | |
|
2663 | 2664 | def formatnode(repo, ctx): |
|
2664 | props['ctx'] = ctx | |
|
2665 | props['repo'] = repo | |
|
2666 | props['revcache'] = {} | |
|
2665 | props = {'ctx': ctx, 'repo': repo, 'revcache': {}} | |
|
2667 | 2666 | return templ.render(props) |
|
2668 | 2667 | return formatnode |
|
2669 | 2668 |
@@ -552,8 +552,7 b' def _formatconflictmarker(ctx, template,' | |||
|
552 | 552 | if ctx.node() is None: |
|
553 | 553 | ctx = ctx.p1() |
|
554 | 554 | |
|
555 | props = templatekw.keywords.copy() | |
|
556 | props['ctx'] = ctx | |
|
555 | props = {'ctx': ctx} | |
|
557 | 556 | templateresult = template.render(props) |
|
558 | 557 | |
|
559 | 558 | label = ('%s:' % label).ljust(pad + 1) |
@@ -580,7 +579,8 b' def _formatlabels(repo, fcd, fco, fca, l' | |||
|
580 | 579 | template = ui.config('ui', 'mergemarkertemplate') |
|
581 | 580 | template = templater.unquotestring(template) |
|
582 | 581 | tres = formatter.templateresources(ui, repo) |
|
583 |
tmpl = formatter.maketemplater(ui, template, |
|
|
582 | tmpl = formatter.maketemplater(ui, template, defaults=templatekw.keywords, | |
|
583 | resources=tres) | |
|
584 | 584 | |
|
585 | 585 | pad = max(len(l) for l in labels) |
|
586 | 586 |
@@ -363,7 +363,8 b' class templateformatter(baseformatter):' | |||
|
363 | 363 | self._out = out |
|
364 | 364 | spec = lookuptemplate(ui, topic, opts.get('template', '')) |
|
365 | 365 | self._tref = spec.ref |
|
366 |
self._t = loadtemplater(ui, spec, |
|
|
366 | self._t = loadtemplater(ui, spec, defaults=templatekw.keywords, | |
|
367 | resources=templateresources(ui), | |
|
367 | 368 | cache=templatekw.defaulttempl) |
|
368 | 369 | self._parts = templatepartsmap(spec, self._t, |
|
369 | 370 | ['docheader', 'docfooter', 'separator']) |
@@ -386,8 +387,6 b' class templateformatter(baseformatter):' | |||
|
386 | 387 | # function will have to declare dependent resources. e.g. |
|
387 | 388 | # @templatekeyword(..., requires=('ctx',)) |
|
388 | 389 | props = {} |
|
389 | if 'ctx' in item: | |
|
390 | props.update(templatekw.keywords) | |
|
391 | 390 | # explicitly-defined fields precede templatekw |
|
392 | 391 | props.update(item) |
|
393 | 392 | if 'ctx' in item: |
@@ -467,19 +466,22 b' def templatepartsmap(spec, t, partnames)' | |||
|
467 | 466 | partsmap[part] = ref |
|
468 | 467 | return partsmap |
|
469 | 468 | |
|
470 | def loadtemplater(ui, spec, resources=None, cache=None): | |
|
469 | def loadtemplater(ui, spec, defaults=None, resources=None, cache=None): | |
|
471 | 470 | """Create a templater from either a literal template or loading from |
|
472 | 471 | a map file""" |
|
473 | 472 | assert not (spec.tmpl and spec.mapfile) |
|
474 | 473 | if spec.mapfile: |
|
475 | 474 | frommapfile = templater.templater.frommapfile |
|
476 |
return frommapfile(spec.mapfile, resources=resources, |
|
|
477 | return maketemplater(ui, spec.tmpl, resources=resources, cache=cache) | |
|
475 | return frommapfile(spec.mapfile, defaults=defaults, resources=resources, | |
|
476 | cache=cache) | |
|
477 | return maketemplater(ui, spec.tmpl, defaults=defaults, resources=resources, | |
|
478 | cache=cache) | |
|
478 | 479 | |
|
479 | def maketemplater(ui, tmpl, resources=None, cache=None): | |
|
480 | def maketemplater(ui, tmpl, defaults=None, resources=None, cache=None): | |
|
480 | 481 | """Create a templater from a string template 'tmpl'""" |
|
481 | 482 | aliases = ui.configitems('templatealias') |
|
482 |
t = templater.templater(resources=resources, |
|
|
483 | t = templater.templater(defaults=defaults, resources=resources, | |
|
484 | cache=cache, aliases=aliases) | |
|
483 | 485 | t.cache.update((k, templater.unquotestring(v)) |
|
484 | 486 | for k, v in ui.configitems('templates')) |
|
485 | 487 | if tmpl: |
@@ -6,11 +6,14 b'' | |||
|
6 | 6 | > class mytemplater(object): |
|
7 | 7 | > def __init__(self, loader, filters, defaults, resources, aliases): |
|
8 | 8 | > self.loader = loader |
|
9 | > self._defaults = defaults | |
|
9 | 10 | > self._resources = resources |
|
10 | 11 | > |
|
11 | 12 | > def process(self, t, map): |
|
12 | 13 | > tmpl = self.loader(t) |
|
13 | > for k, v in map.iteritems(): | |
|
14 | > props = self._defaults.copy() | |
|
15 | > props.update(map) | |
|
16 | > for k, v in props.iteritems(): | |
|
14 | 17 | > if k in ('templ', 'ctx', 'repo', 'revcache', 'cache', 'troubles'): |
|
15 | 18 | > continue |
|
16 | 19 | > if hasattr(v, '__call__'): |
General Comments 0
You need to be logged in to leave comments.
Login now