Mercurial > hg-stable
diff mercurial/registrar.py @ 31886:bdda942f4b9c
templater: add support for keyword arguments
Unlike revset, function arguments are pre-processed in templater. That's why
we need to define argspec per function. An argspec field looks somewhat
redundant in @templatefunc definition as a name field contains human-readable
list of arguments. I'll make function doc be built from argspec later.
Ported separate() function as an example.
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Mon, 03 Apr 2017 21:22:39 +0900 |
parents | 45761ef1bc93 |
children | 46ba2cdda476 |
line wrap: on
line diff
--- a/mercurial/registrar.py Mon Apr 03 20:55:55 2017 +0900 +++ b/mercurial/registrar.py Mon Apr 03 21:22:39 2017 +0900 @@ -234,7 +234,7 @@ templatefunc = registrar.templatefunc() - @templatefunc('myfunc(arg1, arg2[, arg3])') + @templatefunc('myfunc(arg1, arg2[, arg3])', argspec='arg1 arg2 arg3') def myfuncfunc(context, mapping, args): '''Explanation of this template function .... ''' @@ -242,6 +242,10 @@ The first string argument is used also in online help. + If optional 'argspec' is defined, the function will receive 'args' as + a dict of named arguments. Otherwise 'args' is a list of positional + arguments. + 'templatefunc' instance in example above can be used to decorate multiple functions. @@ -252,3 +256,6 @@ Otherwise, explicit 'templater.loadfunction()' is needed. """ _getname = _funcregistrarbase._parsefuncdecl + + def _extrasetup(self, name, func, argspec=None): + func._argspec = argspec