# HG changeset patch # User Pierre-Yves David # Date 1344341300 -7200 # Node ID bd05022c785681dae59815d386d2c09c358708c0 # Parent 07db1d511faf6ba85e625f78ea30b0242907a6a9 obsolete: add and use templatekw decorator diff -r 07db1d511faf -r bd05022c7856 hgext/obsolete.py --- a/hgext/obsolete.py Tue Aug 07 14:00:39 2012 +0200 +++ b/hgext/obsolete.py Tue Aug 07 14:08:20 2012 +0200 @@ -95,6 +95,7 @@ self._extcallables = [] self._repocallables = [] self._revsetsymbols = [] + self._templatekws = [] self._commandwrappers = [] self._extcommandwrappers = [] self._functionwrappers = [] @@ -140,6 +141,8 @@ knownexts = {} for name, symbol in self._revsetsymbols: revset.symbols[name] = symbol + for name, kw in self._templatekws: + templatekw.keywords[name] = kw for ext, command, wrapper in self._extcommandwrappers: if ext not in knownexts: e = extensions.find('rebase') @@ -216,6 +219,24 @@ return symbol return dec + + def templatekw(self, keywordname): + """Decorated function is a revset keyword + + The name of the keyword must be given as the decorator argument. + The symbol is added during `extsetup`. + + example:: + + @eh.templatekw('babar') + def kwbabar(ctx): + return 'babar' + """ + def dec(keyword): + self._templatekws.append((keywordname, keyword)) + return keyword + return dec + def wrapcommand(self, command, extension=None): """Decorated function is a command wrapper @@ -487,6 +508,7 @@ ### template keywords ##################### +@eh.templatekw('obsolete') def obsoletekw(repo, ctx, templ, **args): """:obsolete: String. The obsolescence level of the node, could be ``stable``, ``unstable``, ``suspended`` or ``extinct``. @@ -500,10 +522,6 @@ return 'unstable' return 'stable' -@eh.extsetup -def addkeyword(ui): - templatekw.keywords['obsolete'] = obsoletekw - ### Other Extension compat ############################