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