mercurial/templatekw.py
changeset 36521 c3692364b344
parent 36520 a7fbe11a5d59
child 36574 45f149bf08d1
equal deleted inserted replaced
36520:a7fbe11a5d59 36521:c3692364b344
   145     """
   145     """
   146     c = [{key: k, value: v} for k, v in data.iteritems()]
   146     c = [{key: k, value: v} for k, v in data.iteritems()]
   147     t = context.resource(mapping, 'templ')
   147     t = context.resource(mapping, 'templ')
   148     f = _showlist(name, c, t, mapping, plural, separator)
   148     f = _showlist(name, c, t, mapping, plural, separator)
   149     return hybriddict(data, key=key, value=value, fmt=fmt, gen=f)
   149     return hybriddict(data, key=key, value=value, fmt=fmt, gen=f)
       
   150 
       
   151 def compatlist(context, mapping, name, data, element=None, fmt='%s',
       
   152                plural=None, separator=' '):
       
   153     """Wrap data like hybridlist(), but also supports old-style list template
       
   154 
       
   155     This exists for backward compatibility with the old-style template. Use
       
   156     hybridlist() for new template keywords.
       
   157     """
       
   158     t = context.resource(mapping, 'templ')
       
   159     f = _showlist(name, data, t, mapping, plural, separator)
       
   160     return hybridlist(data, name=element or name, fmt=fmt, gen=f)
   150 
   161 
   151 def showdict(name, data, mapping, plural=None, key='key', value='value',
   162 def showdict(name, data, mapping, plural=None, key='key', value='value',
   152              fmt='%s=%s', separator=' '):
   163              fmt='%s=%s', separator=' '):
   153     c = [{key: k, value: v} for k, v in data.iteritems()]
   164     c = [{key: k, value: v} for k, v in data.iteritems()]
   154     f = _showlist(name, c, mapping['templ'], mapping, plural, separator)
   165     f = _showlist(name, c, mapping['templ'], mapping, plural, separator)
   395     active = repo._activebookmark
   406     active = repo._activebookmark
   396     makemap = lambda v: {'bookmark': v, 'active': active, 'current': active}
   407     makemap = lambda v: {'bookmark': v, 'active': active, 'current': active}
   397     f = _showlist('bookmark', bookmarks, args['templ'], args)
   408     f = _showlist('bookmark', bookmarks, args['templ'], args)
   398     return _hybrid(f, bookmarks, makemap, pycompat.identity)
   409     return _hybrid(f, bookmarks, makemap, pycompat.identity)
   399 
   410 
   400 @templatekeyword('children')
   411 @templatekeyword('children', requires={'ctx', 'templ'})
   401 def showchildren(**args):
   412 def showchildren(context, mapping):
   402     """List of strings. The children of the changeset."""
   413     """List of strings. The children of the changeset."""
   403     args = pycompat.byteskwargs(args)
   414     ctx = context.resource(mapping, 'ctx')
   404     ctx = args['ctx']
       
   405     childrevs = ['%d:%s' % (cctx.rev(), cctx) for cctx in ctx.children()]
   415     childrevs = ['%d:%s' % (cctx.rev(), cctx) for cctx in ctx.children()]
   406     return showlist('children', childrevs, args, element='child')
   416     return compatlist(context, mapping, 'children', childrevs, element='child')
   407 
   417 
   408 # Deprecated, but kept alive for help generation a purpose.
   418 # Deprecated, but kept alive for help generation a purpose.
   409 @templatekeyword('currentbookmark', requires={'repo', 'ctx'})
   419 @templatekeyword('currentbookmark', requires={'repo', 'ctx'})
   410 def showcurrentbookmark(context, mapping):
   420 def showcurrentbookmark(context, mapping):
   411     """String. The active bookmark, if it is associated with the changeset.
   421     """String. The active bookmark, if it is associated with the changeset.