diff mercurial/hgweb/hgwebdir_mod.py @ 37019:c97b936d8bb5

templater: use named function to expand template against mapping dict (API) And replace __call__(t, **mapping) in favor of generate(t, mapping). I prefer a named function here since the templater isn't a simple function-like object. .. api:: The templater is no longer callable. Use ``templater.generate(t, mapping)`` instead of ``templater(t, **pycompat.strkwargs(mapping))``.
author Yuya Nishihara <yuya@tcha.org>
date Fri, 16 Mar 2018 21:39:32 +0900
parents de117f579431
children 30a7b32897f1
line wrap: on
line diff
--- a/mercurial/hgweb/hgwebdir_mod.py	Mon Mar 19 21:09:23 2018 +0900
+++ b/mercurial/hgweb/hgwebdir_mod.py	Fri Mar 16 21:39:32 2018 +0900
@@ -452,12 +452,12 @@
 
             # prefixes not found
             res.status = '404 Not Found'
-            res.setbodygen(tmpl('notfound', repo=virtual))
+            res.setbodygen(tmpl.generate('notfound', {'repo': virtual}))
             return res.sendresponse()
 
         except ErrorResponse as e:
             res.status = statusmessage(e.code, pycompat.bytestr(e))
-            res.setbodygen(tmpl('error', error=e.message or ''))
+            res.setbodygen(tmpl.generate('error', {'error': e.message or ''}))
             return res.sendresponse()
         finally:
             tmpl = None
@@ -485,15 +485,15 @@
                                self.stripecount, sortcolumn=sortcolumn,
                                descending=descending, subdir=subdir)
 
-        res.setbodygen(tmpl(
-            'index',
-            entries=entries,
-            subdir=subdir,
-            pathdef=hgweb_mod.makebreadcrumb('/' + subdir, self.prefix),
-            sortcolumn=sortcolumn,
-            descending=descending,
-            **dict(sort)))
-
+        mapping = {
+            'entries': entries,
+            'subdir': subdir,
+            'pathdef': hgweb_mod.makebreadcrumb('/' + subdir, self.prefix),
+            'sortcolumn': sortcolumn,
+            'descending': descending,
+        }
+        mapping.update(sort)
+        res.setbodygen(tmpl.generate('index', mapping))
         return res.sendresponse()
 
     def templater(self, req, nonce):