diff mercurial/templatekw.py @ 31807:e6eb86b154c5

templater: provide loop counter as "index" keyword This was originally written for JSON templating where we would have to be careful to not add extra comma, but seems generally useful. Inner loop started by % operator has its own counter.
author Yuya Nishihara <yuya@tcha.org>
date Fri, 22 Apr 2016 21:46:33 +0900
parents 568c4e7437b2
children f0d719e513fc
line wrap: on
line diff
--- a/mercurial/templatekw.py	Fri Apr 22 21:45:06 2016 +0900
+++ b/mercurial/templatekw.py	Fri Apr 22 21:46:33 2016 +0900
@@ -7,6 +7,7 @@
 
 from __future__ import absolute_import
 
+from .i18n import _
 from .node import hex, nullid
 from . import (
     encoding,
@@ -422,6 +423,12 @@
     else:
         return 'o'
 
+@templatekeyword('index')
+def showindex(**args):
+    """Integer. The current iteration of the loop. (0 indexed)"""
+    # just hosts documentation; should be overridden by template mapping
+    raise error.Abort(_("can't use index in this context"))
+
 @templatekeyword('latesttag')
 def showlatesttag(**args):
     """List of strings. The global tags on the most recent globally