Show More
@@ -501,14 +501,23 b' def maketemplater(ui, tmpl, defaults=Non' | |||
|
501 | 501 | def templateresources(ui, repo=None): |
|
502 | 502 | """Create a dict of template resources designed for the default templatekw |
|
503 | 503 | and function""" |
|
504 |
re |
|
|
504 | resmap = { | |
|
505 | 505 | 'cache': {}, # for templatekw/funcs to store reusable data |
|
506 | 'ctx': None, | |
|
507 | 506 | 'repo': repo, |
|
508 | 'revcache': None, # per-ctx cache; set later | |
|
509 | 507 | 'ui': ui, |
|
510 | 508 | } |
|
511 | 509 | |
|
510 | def getsome(context, mapping, key): | |
|
511 | return resmap.get(key) | |
|
512 | ||
|
513 | return { | |
|
514 | 'cache': getsome, | |
|
515 | 'ctx': getsome, | |
|
516 | 'repo': getsome, | |
|
517 | 'revcache': getsome, # per-ctx cache; set later | |
|
518 | 'ui': getsome, | |
|
519 | } | |
|
520 | ||
|
512 | 521 | def formatter(ui, out, topic, opts): |
|
513 | 522 | template = opts.get("template", "") |
|
514 | 523 | if template == "json": |
@@ -423,7 +423,7 b' class changesettemplater(changesetprinte' | |||
|
423 | 423 | resources=tres, |
|
424 | 424 | cache=templatekw.defaulttempl) |
|
425 | 425 | self._counter = itertools.count() |
|
426 | self.cache = tres['cache'] # shared with _graphnodeformatter() | |
|
426 | self._getcache = tres['cache'] # shared with _graphnodeformatter() | |
|
427 | 427 | |
|
428 | 428 | self._tref = tmplspec.ref |
|
429 | 429 | self._parts = {'header': '', 'footer': '', |
@@ -852,7 +852,8 b' def _graphnodeformatter(ui, displayer):' | |||
|
852 | 852 | spec = templater.unquotestring(spec) |
|
853 | 853 | tres = formatter.templateresources(ui) |
|
854 | 854 | if isinstance(displayer, changesettemplater): |
|
855 |
|
|
|
855 | # reuse cache of slow templates | |
|
856 | tres['cache'] = displayer._getcache | |
|
856 | 857 | templ = formatter.maketemplater(ui, spec, defaults=templatekw.keywords, |
|
857 | 858 | resources=tres) |
|
858 | 859 | def formatnode(repo, ctx): |
@@ -566,8 +566,8 b' class engine(object):' | |||
|
566 | 566 | v = None |
|
567 | 567 | if key in self._resources: |
|
568 | 568 | v = mapping.get(key) |
|
569 | if v is None: | |
|
570 |
v = self._resources |
|
|
569 | if v is None and key in self._resources: | |
|
570 | v = self._resources[key](self, mapping, key) | |
|
571 | 571 | if v is None: |
|
572 | 572 | raise templateutil.ResourceUnavailable( |
|
573 | 573 | _('template resource not available: %s') % key) |
@@ -670,8 +670,9 b' class templater(object):' | |||
|
670 | 670 | - ``filters``: a dict of functions to transform a value into another. |
|
671 | 671 | - ``defaults``: a dict of symbol values/functions; may be overridden |
|
672 | 672 | by a ``mapping`` dict. |
|
673 |
- ``resources``: a dict of internal data |
|
|
674 |
from user template; may be overridden by |
|
|
673 | - ``resources``: a dict of functions returning internal data | |
|
674 | (e.g. cache), inaccessible from user template; may be overridden by | |
|
675 | a ``mapping`` dict. | |
|
675 | 676 | - ``cache``: a dict of preloaded template fragments. |
|
676 | 677 | - ``aliases``: a list of alias (name, replacement) pairs. |
|
677 | 678 | |
@@ -691,7 +692,7 b' class templater(object):' | |||
|
691 | 692 | self.filters = templatefilters.filters.copy() |
|
692 | 693 | self.filters.update(filters) |
|
693 | 694 | self.defaults = defaults |
|
694 | self._resources = {'templ': self} | |
|
695 | self._resources = {'templ': lambda context, mapping, key: self} | |
|
695 | 696 | self._resources.update(resources) |
|
696 | 697 | self._aliases = aliases |
|
697 | 698 | self.minchunk, self.maxchunk = minchunk, maxchunk |
@@ -350,7 +350,8 b' def runsymbol(context, mapping, key, def' | |||
|
350 | 350 | v = default |
|
351 | 351 | if callable(v) and getattr(v, '_requires', None) is None: |
|
352 | 352 | # old templatekw: expand all keywords and resources |
|
353 |
props = context |
|
|
353 | props = {k: f(context, mapping, k) | |
|
354 | for k, f in context._resources.items()} | |
|
354 | 355 | props.update(mapping) |
|
355 | 356 | return v(**pycompat.strkwargs(props)) |
|
356 | 357 | if callable(v): |
General Comments 0
You need to be logged in to leave comments.
Login now