Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/templateutil.py @ 36985:255f635c3204
templater: convert resources to a table of callables for future extension
I'm going to add a full templating support to the annotate command. As the
annotate is a filectx-oriented command, we'll need a way to look up a ctx
from a bounded fctx only when necessary.
This is the minimal change to support that. I'm thinking of defining a proper
interface to look up template resources to fix other issues, but that isn't
ready yet.
(Changes from V1: just updated tests and patch descriptions.)
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Sun, 11 Mar 2018 21:05:29 +0900 |
parents | 32f9b7e3f056 |
children | c97b936d8bb5 |
comparison
equal
deleted
inserted
replaced
36984:c479692690ef | 36985:255f635c3204 |
---|---|
348 v = context.process(key, safemapping) | 348 v = context.process(key, safemapping) |
349 except TemplateNotFound: | 349 except TemplateNotFound: |
350 v = default | 350 v = default |
351 if callable(v) and getattr(v, '_requires', None) is None: | 351 if callable(v) and getattr(v, '_requires', None) is None: |
352 # old templatekw: expand all keywords and resources | 352 # old templatekw: expand all keywords and resources |
353 props = context._resources.copy() | 353 props = {k: f(context, mapping, k) |
354 for k, f in context._resources.items()} | |
354 props.update(mapping) | 355 props.update(mapping) |
355 return v(**pycompat.strkwargs(props)) | 356 return v(**pycompat.strkwargs(props)) |
356 if callable(v): | 357 if callable(v): |
357 # new templatekw | 358 # new templatekw |
358 try: | 359 try: |