##// END OF EJS Templates
templatekw: add compatdict() as a replacement for showdict()...
Yuya Nishihara -
r36537:a7fbe11a default
parent child Browse files
Show More
@@ -136,6 +136,18 b' def wraphybridvalue(container, key, valu'
136 136 return value
137 137 return _mappable(None, key, value, makemap)
138 138
139 def compatdict(context, mapping, name, data, key='key', value='value',
140 fmt='%s=%s', plural=None, separator=' '):
141 """Wrap data like hybriddict(), but also supports old-style list template
142
143 This exists for backward compatibility with the old-style template. Use
144 hybriddict() for new template keywords.
145 """
146 c = [{key: k, value: v} for k, v in data.iteritems()]
147 t = context.resource(mapping, 'templ')
148 f = _showlist(name, c, t, mapping, plural, separator)
149 return hybriddict(data, key=key, value=value, fmt=fmt, gen=f)
150
139 151 def showdict(name, data, mapping, plural=None, key='key', value='value',
140 152 fmt='%s=%s', separator=' '):
141 153 c = [{key: k, value: v} for k, v in data.iteritems()]
@@ -437,13 +449,13 b' def showdiffstat(context, mapping):'
437 449 maxname, maxtotal, adds, removes, binary = patch.diffstatsum(stats)
438 450 return '%d: +%d/-%d' % (len(stats), adds, removes)
439 451
440 @templatekeyword('envvars')
441 def showenvvars(ui, **args):
452 @templatekeyword('envvars', requires={'ui', 'templ'})
453 def showenvvars(context, mapping):
442 454 """A dictionary of environment variables. (EXPERIMENTAL)"""
443 args = pycompat.byteskwargs(args)
455 ui = context.resource(mapping, 'ui')
444 456 env = ui.exportableenviron()
445 457 env = util.sortdict((k, env[k]) for k in sorted(env))
446 return showdict('envvar', env, args, plural='envvars')
458 return compatdict(context, mapping, 'envvar', env, plural='envvars')
447 459
448 460 @templatekeyword('extras')
449 461 def showextras(**args):
General Comments 0
You need to be logged in to leave comments. Login now