##// END OF EJS Templates
templatekw: factor out showdict() helper...
Yuya Nishihara -
r32038:3920b597 default
parent child Browse files
Show More
@@ -78,6 +78,12 b' def unwraphybrid(thing):'
78 78 return thing
79 79 return thing.gen
80 80
81 def showdict(name, data, mapping, plural=None, key='key', value='value',
82 fmt='%s=%s', separator=' '):
83 c = [{key: k, value: v} for k, v in data.iteritems()]
84 f = _showlist(name, c, mapping, plural, separator)
85 return hybriddict(data, key=key, value=value, fmt=fmt, gen=f)
86
81 87 def showlist(name, values, mapping, plural=None, element=None, separator=' '):
82 88 if not element:
83 89 element = name
@@ -348,14 +354,9 b' def showdiffstat(repo, ctx, templ, **arg'
348 354 @templatekeyword('envvars')
349 355 def showenvvars(repo, **args):
350 356 """A dictionary of environment variables. (EXPERIMENTAL)"""
351
352 357 env = repo.ui.exportableenviron()
353 358 env = util.sortdict((k, env[k]) for k in sorted(env))
354 makemap = lambda k: {'key': k, 'value': env[k]}
355 c = [makemap(k) for k in env]
356 f = _showlist('envvar', c, args, plural='envvars')
357 return _hybrid(f, env, makemap,
358 lambda x: '%s=%s' % (x['key'], x['value']))
359 return showdict('envvar', env, args, plural='envvars')
359 360
360 361 @templatekeyword('extras')
361 362 def showextras(**args):
@@ -394,11 +395,8 b' def showfilecopies(**args):'
394 395 copies.append((fn, rename[0]))
395 396
396 397 copies = util.sortdict(copies)
397 makemap = lambda k: {'name': k, 'source': copies[k]}
398 c = [makemap(k) for k in copies]
399 f = _showlist('file_copy', c, args, plural='file_copies')
400 return _hybrid(f, copies, makemap,
401 lambda x: '%s (%s)' % (x['name'], x['source']))
398 return showdict('file_copy', copies, args, plural='file_copies',
399 key='name', value='source', fmt='%s (%s)')
402 400
403 401 # showfilecopiesswitch() displays file copies only if copy records are
404 402 # provided before calling the templater, usually with a --copies
@@ -410,11 +408,8 b' def showfilecopiesswitch(**args):'
410 408 """
411 409 copies = args['revcache'].get('copies') or []
412 410 copies = util.sortdict(copies)
413 makemap = lambda k: {'name': k, 'source': copies[k]}
414 c = [makemap(k) for k in copies]
415 f = _showlist('file_copy', c, args, plural='file_copies')
416 return _hybrid(f, copies, makemap,
417 lambda x: '%s (%s)' % (x['name'], x['source']))
411 return showdict('file_copy', copies, args, plural='file_copies',
412 key='name', value='source', fmt='%s (%s)')
418 413
419 414 @templatekeyword('file_dels')
420 415 def showfiledels(**args):
General Comments 0
You need to be logged in to leave comments. Login now