comparison mercurial/formatter.py @ 35470:a33be093ec62

templater: look up symbols/resources as if they were separated (issue5699) It wouldn't be easy to split the mapping dict into (symbols, resources). This patch instead rejects invalid lookup taking resources.keys() as source of truth. The doctest is updated since mapping['repo'] is now reserved for a repo object.
author Yuya Nishihara <yuya@tcha.org>
date Thu, 21 Dec 2017 22:17:39 +0900
parents f1c54d003327
children 817a3d20dd01
comparison
equal deleted inserted replaced
35469:f1c54d003327 35470:a33be093ec62
92 92
93 Nested example: 93 Nested example:
94 94
95 >>> def subrepos(ui, fm): 95 >>> def subrepos(ui, fm):
96 ... fm.startitem() 96 ... fm.startitem()
97 ... fm.write(b'repo', b'[%s]\\n', b'baz') 97 ... fm.write(b'reponame', b'[%s]\\n', b'baz')
98 ... files(ui, fm.nested(b'files')) 98 ... files(ui, fm.nested(b'files'))
99 ... fm.end() 99 ... fm.end()
100 >>> show(subrepos) 100 >>> show(subrepos)
101 [baz] 101 [baz]
102 foo 102 foo
103 bar 103 bar
104 >>> show(subrepos, template=b'{repo}: {join(files % "{path}", ", ")}\\n') 104 >>> show(subrepos, template=b'{reponame}: {join(files % "{path}", ", ")}\\n')
105 baz: foo, bar 105 baz: foo, bar
106 """ 106 """
107 107
108 from __future__ import absolute_import, print_function 108 from __future__ import absolute_import, print_function
109 109
489 def templateresources(ui, repo=None): 489 def templateresources(ui, repo=None):
490 """Create a dict of template resources designed for the default templatekw 490 """Create a dict of template resources designed for the default templatekw
491 and function""" 491 and function"""
492 return { 492 return {
493 'cache': {}, # for templatekw/funcs to store reusable data 493 'cache': {}, # for templatekw/funcs to store reusable data
494 'ctx': None,
494 'repo': repo, 495 'repo': repo,
496 'revcache': None, # per-ctx cache; set later
495 'ui': ui, 497 'ui': ui,
496 } 498 }
497 499
498 def formatter(ui, out, topic, opts): 500 def formatter(ui, out, topic, opts):
499 template = opts.get("template", "") 501 template = opts.get("template", "")