Mercurial > public > mercurial-scm > hg
comparison mercurial/templateutil.py @ 42337:832c59d1196e
templater: drop support for old style keywords (API)
These changes originated from several commits over a period of time, so I'm
slightly unsure if this is correct. But the tests pass.
author | Matt Harbison <matt_harbison@yahoo.com> |
---|---|
date | Sat, 18 May 2019 19:56:06 -0400 |
parents | 4591c9791a82 |
children | 2372284d9457 |
comparison
equal
deleted
inserted
replaced
42336:fa4b13e81f60 | 42337:832c59d1196e |
---|---|
872 return data | 872 return data |
873 | 873 |
874 def _recursivesymbolblocker(key): | 874 def _recursivesymbolblocker(key): |
875 def showrecursion(context, mapping): | 875 def showrecursion(context, mapping): |
876 raise error.Abort(_("recursive reference '%s' in template") % key) | 876 raise error.Abort(_("recursive reference '%s' in template") % key) |
877 showrecursion._requires = () # mark as new-style templatekw | |
878 return showrecursion | 877 return showrecursion |
879 | 878 |
880 def runsymbol(context, mapping, key, default=''): | 879 def runsymbol(context, mapping, key, default=''): |
881 v = context.symbol(mapping, key) | 880 v = context.symbol(mapping, key) |
882 if v is None: | 881 if v is None: |
886 safemapping[key] = _recursivesymbolblocker(key) | 885 safemapping[key] = _recursivesymbolblocker(key) |
887 try: | 886 try: |
888 v = context.process(key, safemapping) | 887 v = context.process(key, safemapping) |
889 except TemplateNotFound: | 888 except TemplateNotFound: |
890 v = default | 889 v = default |
891 if callable(v) and getattr(v, '_requires', None) is None: | |
892 # old templatekw: expand all keywords and resources | |
893 # (TODO: drop support for old-style functions. 'f._requires = ()' | |
894 # can be removed.) | |
895 props = {k: context._resources.lookup(mapping, k) | |
896 for k in context._resources.knownkeys()} | |
897 # pass context to _showcompatlist() through templatekw._showlist() | |
898 props['templ'] = context | |
899 props.update(mapping) | |
900 ui = props.get('ui') | |
901 if ui: | |
902 ui.deprecwarn("old-style template keyword '%s'" % key, '4.8') | |
903 return v(**pycompat.strkwargs(props)) | |
904 if callable(v): | 890 if callable(v): |
905 # new templatekw | 891 # new templatekw |
906 try: | 892 try: |
907 return v(context, mapping) | 893 return v(context, mapping) |
908 except ResourceUnavailable: | 894 except ResourceUnavailable: |