comparison mercurial/cmdutil.py @ 35468:32c278eb876f

templater: keep default resources per template engine (API) This allows us to register a repo object as a resource in hgweb template, without loosing '{repo}' symbol: symbol('repo') -> mapping['repo'] (n/a) -> defaults['repo'] resource('repo') -> mapping['repo'] (n/a) -> resources['repo'] I'm thinking of redesigning the templatekw API to take (context, mapping) in place of **(context._resources + mapping), but that will be a big change and not implemented yet. props['templ'] is ported to the resources dict as an example. .. api:: mapping does not contain all template resources. use context.resource() in template functions.
author Yuya Nishihara <yuya@tcha.org>
date Thu, 21 Dec 2017 21:29:06 +0900
parents 5bec509dc1ff
children f1c54d003327
comparison
equal deleted inserted replaced
35467:d6cfa722b044 35468:32c278eb876f
1884 1884
1885 def _show(self, ctx, copies, matchfn, hunksfilterfn, props): 1885 def _show(self, ctx, copies, matchfn, hunksfilterfn, props):
1886 '''show a single changeset or file revision''' 1886 '''show a single changeset or file revision'''
1887 props = props.copy() 1887 props = props.copy()
1888 props.update(templatekw.keywords) 1888 props.update(templatekw.keywords)
1889 props['templ'] = self.t
1890 props['ctx'] = ctx 1889 props['ctx'] = ctx
1891 props['repo'] = self.repo 1890 props['repo'] = self.repo
1892 props['ui'] = self.repo.ui 1891 props['ui'] = self.repo.ui
1893 props['index'] = index = next(self._counter) 1892 props['index'] = index = next(self._counter)
1894 props['revcache'] = {'copies': copies} 1893 props['revcache'] = {'copies': copies}
2661 templ = formatter.maketemplater(ui, spec) 2660 templ = formatter.maketemplater(ui, spec)
2662 cache = {} 2661 cache = {}
2663 if isinstance(displayer, changeset_templater): 2662 if isinstance(displayer, changeset_templater):
2664 cache = displayer.cache # reuse cache of slow templates 2663 cache = displayer.cache # reuse cache of slow templates
2665 props = templatekw.keywords.copy() 2664 props = templatekw.keywords.copy()
2666 props['templ'] = templ
2667 props['cache'] = cache 2665 props['cache'] = cache
2668 def formatnode(repo, ctx): 2666 def formatnode(repo, ctx):
2669 props['ctx'] = ctx 2667 props['ctx'] = ctx
2670 props['repo'] = repo 2668 props['repo'] = repo
2671 props['ui'] = repo.ui 2669 props['ui'] = repo.ui