##// END OF EJS Templates
hgweb: use templater on requestcontext instance...
Gregory Szorc -
r36900:ece242db default
parent child Browse files
Show More
@@ -58,8 +58,8 b' def pygmentize(web, field, fctx, tmpl):'
58 58 highlight.pygmentize(field, fctx, style, tmpl,
59 59 guessfilenameonly=filenameonly)
60 60
61 def filerevision_highlight(orig, web, req, tmpl, fctx):
62 mt = ''.join(tmpl('mimetype', encoding=encoding.encoding))
61 def filerevision_highlight(orig, web, req, fctx):
62 mt = ''.join(web.tmpl('mimetype', encoding=encoding.encoding))
63 63 # only pygmentize for mimetype containing 'html' so we both match
64 64 # 'text/html' and possibly 'application/xhtml+xml' in the future
65 65 # so that we don't have to touch the extension when the mimetype
@@ -68,17 +68,17 b' def filerevision_highlight(orig, web, re'
68 68 # can't clash with the file's content-type here in case we
69 69 # pygmentize a html file
70 70 if 'html' in mt:
71 pygmentize(web, 'fileline', fctx, tmpl)
71 pygmentize(web, 'fileline', fctx, web.tmpl)
72 72
73 return orig(web, req, tmpl, fctx)
73 return orig(web, req, fctx)
74 74
75 75 def annotate_highlight(orig, web, req, tmpl):
76 mt = ''.join(tmpl('mimetype', encoding=encoding.encoding))
76 mt = ''.join(web.tmpl('mimetype', encoding=encoding.encoding))
77 77 if 'html' in mt:
78 78 fctx = webutil.filectx(web.repo, req)
79 pygmentize(web, 'annotateline', fctx, tmpl)
79 pygmentize(web, 'annotateline', fctx, web.tmpl)
80 80
81 return orig(web, req, tmpl)
81 return orig(web, req, web.tmpl)
82 82
83 83 def generate_css(web, req, tmpl):
84 84 pg_style = web.config('web', 'pygments_style', 'colorful')
@@ -95,9 +95,9 b' def log(web, req, tmpl):'
95 95 """
96 96
97 97 if web.req.qsparams.get('file'):
98 return filelog(web, req, tmpl)
98 return filelog(web, req, None)
99 99 else:
100 return changelog(web, req, tmpl)
100 return changelog(web, req, None)
101 101
102 102 @webcommand('rawfile')
103 103 def rawfile(web, req, tmpl):
@@ -105,13 +105,13 b' def rawfile(web, req, tmpl):'
105 105
106 106 path = webutil.cleanpath(web.repo, web.req.qsparams.get('file', ''))
107 107 if not path:
108 return manifest(web, req, tmpl)
108 return manifest(web, req, None)
109 109
110 110 try:
111 111 fctx = webutil.filectx(web.repo, req)
112 112 except error.LookupError as inst:
113 113 try:
114 return manifest(web, req, tmpl)
114 return manifest(web, req, None)
115 115 except ErrorResponse:
116 116 raise inst
117 117
@@ -135,7 +135,7 b' def rawfile(web, req, tmpl):'
135 135 web.res.setbodybytes(text)
136 136 return web.res.sendresponse()
137 137
138 def _filerevision(web, req, tmpl, fctx):
138 def _filerevision(web, req, fctx):
139 139 f = fctx.path()
140 140 text = fctx.data()
141 141 parity = paritygen(web.stripecount)
@@ -184,20 +184,20 b' def file(web, req, tmpl):'
184 184 be rendered.
185 185 """
186 186 if web.req.qsparams.get('style') == 'raw':
187 return rawfile(web, req, tmpl)
187 return rawfile(web, req, None)
188 188
189 189 path = webutil.cleanpath(web.repo, web.req.qsparams.get('file', ''))
190 190 if not path:
191 return manifest(web, req, tmpl)
191 return manifest(web, req, None)
192 192 try:
193 return _filerevision(web, req, tmpl, webutil.filectx(web.repo, req))
193 return _filerevision(web, req, webutil.filectx(web.repo, req))
194 194 except error.LookupError as inst:
195 195 try:
196 return manifest(web, req, tmpl)
196 return manifest(web, req, None)
197 197 except ErrorResponse:
198 198 raise inst
199 199
200 def _search(web, tmpl):
200 def _search(web):
201 201 MODE_REVISION = 'rev'
202 202 MODE_KEYWORD = 'keyword'
203 203 MODE_REVSET = 'revset'
@@ -290,14 +290,16 b' def _search(web, tmpl):'
290 290 for ctx in searchfunc[0](funcarg):
291 291 count += 1
292 292 n = ctx.node()
293 showtags = webutil.showtag(web.repo, tmpl, 'changelogtag', n)
294 files = webutil.listfilediffs(tmpl, ctx.files(), n, web.maxfiles)
293 showtags = webutil.showtag(web.repo, web.tmpl, 'changelogtag', n)
294 files = webutil.listfilediffs(web.tmpl, ctx.files(), n,
295 web.maxfiles)
295 296
296 yield tmpl('searchentry',
297 parity=next(parity),
298 changelogtag=showtags,
299 files=files,
300 **pycompat.strkwargs(webutil.commonentry(web.repo, ctx)))
297 yield web.tmpl(
298 'searchentry',
299 parity=next(parity),
300 changelogtag=showtags,
301 files=files,
302 **pycompat.strkwargs(webutil.commonentry(web.repo, ctx)))
301 303
302 304 if count >= revcount:
303 305 break
@@ -308,14 +310,14 b' def _search(web, tmpl):'
308 310 try:
309 311 revcount = int(web.req.qsparams.get('revcount', revcount))
310 312 revcount = max(revcount, 1)
311 tmpl.defaults['sessionvars']['revcount'] = revcount
313 web.tmpl.defaults['sessionvars']['revcount'] = revcount
312 314 except ValueError:
313 315 pass
314 316
315 lessvars = copy.copy(tmpl.defaults['sessionvars'])
317 lessvars = copy.copy(web.tmpl.defaults['sessionvars'])
316 318 lessvars['revcount'] = max(revcount // 2, 1)
317 319 lessvars['rev'] = query
318 morevars = copy.copy(tmpl.defaults['sessionvars'])
320 morevars = copy.copy(web.tmpl.defaults['sessionvars'])
319 321 morevars['revcount'] = revcount * 2
320 322 morevars['rev'] = query
321 323
@@ -382,7 +384,7 b' def changelog(web, req, tmpl, shortlog=F'
382 384 ctx = webutil.changectx(web.repo, req)
383 385 symrev = webutil.symrevorshortnode(req, ctx)
384 386 elif 'rev' in web.req.qsparams:
385 return _search(web, tmpl)
387 return _search(web)
386 388 else:
387 389 ctx = web.repo['tip']
388 390 symrev = 'tip'
@@ -397,7 +399,7 b' def changelog(web, req, tmpl, shortlog=F'
397 399 if curcount > revcount + 1:
398 400 break
399 401
400 entry = webutil.changelistentry(web, web.repo[rev], tmpl)
402 entry = webutil.changelistentry(web, web.repo[rev], web.tmpl)
401 403 entry['parity'] = next(parity)
402 404 yield entry
403 405
@@ -410,13 +412,13 b' def changelog(web, req, tmpl, shortlog=F'
410 412 try:
411 413 revcount = int(web.req.qsparams.get('revcount', revcount))
412 414 revcount = max(revcount, 1)
413 tmpl.defaults['sessionvars']['revcount'] = revcount
415 web.tmpl.defaults['sessionvars']['revcount'] = revcount
414 416 except ValueError:
415 417 pass
416 418
417 lessvars = copy.copy(tmpl.defaults['sessionvars'])
419 lessvars = copy.copy(web.tmpl.defaults['sessionvars'])
418 420 lessvars['revcount'] = max(revcount // 2, 1)
419 morevars = copy.copy(tmpl.defaults['sessionvars'])
421 morevars = copy.copy(web.tmpl.defaults['sessionvars'])
420 422 morevars['revcount'] = revcount * 2
421 423
422 424 count = len(web.repo)
@@ -461,7 +463,7 b' def shortlog(web, req, tmpl):'
461 463 difference is the ``shortlog`` template will be rendered instead of the
462 464 ``changelog`` template.
463 465 """
464 return changelog(web, req, tmpl, shortlog=True)
466 return changelog(web, req, None, shortlog=True)
465 467
466 468 @webcommand('changeset')
467 469 def changeset(web, req, tmpl):
@@ -483,7 +485,7 b' def changeset(web, req, tmpl):'
483 485
484 486 return web.sendtemplate(
485 487 'changeset',
486 **webutil.changesetentry(web, req, tmpl, ctx))
488 **webutil.changesetentry(web, req, web.tmpl, ctx))
487 489
488 490 rev = webcommand('rev')(changeset)
489 491
@@ -717,11 +719,12 b' def summary(web, req, tmpl):'
717 719 if count > 10: # limit to 10 tags
718 720 break
719 721
720 yield tmpl("tagentry",
721 parity=next(parity),
722 tag=k,
723 node=hex(n),
724 date=web.repo[n].date())
722 yield web.tmpl(
723 'tagentry',
724 parity=next(parity),
725 tag=k,
726 node=hex(n),
727 date=web.repo[n].date())
725 728
726 729 def bookmarks(**map):
727 730 parity = paritygen(web.stripecount)
@@ -743,7 +746,7 b' def summary(web, req, tmpl):'
743 746 for i in revs:
744 747 ctx = web.repo[i]
745 748
746 l.append(tmpl(
749 l.append(web.tmpl(
747 750 'shortlogentry',
748 751 parity=next(parity),
749 752 **pycompat.strkwargs(webutil.commonentry(web.repo, ctx))))
@@ -805,7 +808,7 b' def filediff(web, req, tmpl):'
805 808 if 'style' in web.req.qsparams:
806 809 style = web.req.qsparams['style']
807 810
808 diffs = webutil.diffs(web, tmpl, ctx, basectx, [path], style)
811 diffs = webutil.diffs(web, web.tmpl, ctx, basectx, [path], style)
809 812 if fctx is not None:
810 813 rename = webutil.renamelink(fctx)
811 814 ctx = fctx
@@ -878,7 +881,7 b' def comparison(web, req, tmpl):'
878 881 pfctx = ctx.parents()[0][path]
879 882 leftlines = filelines(pfctx)
880 883
881 comparison = webutil.compare(tmpl, context, leftlines, rightlines)
884 comparison = webutil.compare(web.tmpl, context, leftlines, rightlines)
882 885 if fctx is not None:
883 886 rename = webutil.renamelink(fctx)
884 887 ctx = fctx
@@ -1028,15 +1031,15 b' def filelog(web, req, tmpl):'
1028 1031 try:
1029 1032 revcount = int(web.req.qsparams.get('revcount', revcount))
1030 1033 revcount = max(revcount, 1)
1031 tmpl.defaults['sessionvars']['revcount'] = revcount
1034 web.tmpl.defaults['sessionvars']['revcount'] = revcount
1032 1035 except ValueError:
1033 1036 pass
1034 1037
1035 1038 lrange = webutil.linerange(req)
1036 1039
1037 lessvars = copy.copy(tmpl.defaults['sessionvars'])
1040 lessvars = copy.copy(web.tmpl.defaults['sessionvars'])
1038 1041 lessvars['revcount'] = max(revcount // 2, 1)
1039 morevars = copy.copy(tmpl.defaults['sessionvars'])
1042 morevars = copy.copy(web.tmpl.defaults['sessionvars'])
1040 1043 morevars['revcount'] = revcount * 2
1041 1044
1042 1045 patch = 'patch' in web.req.qsparams
@@ -1063,7 +1066,7 b' def filelog(web, req, tmpl):'
1063 1066 ctx = fctx.changectx()
1064 1067 basectx = ctx.p1()
1065 1068 path = fctx.path()
1066 return webutil.diffs(web, tmpl, ctx, basectx, [path], diffstyle,
1069 return webutil.diffs(web, web.tmpl, ctx, basectx, [path], diffstyle,
1067 1070 linerange=linerange,
1068 1071 lineidprefix='%s-' % ctx.hex()[:12])
1069 1072
@@ -1255,17 +1258,17 b' def graph(web, req, tmpl):'
1255 1258 try:
1256 1259 revcount = int(web.req.qsparams.get('revcount', revcount))
1257 1260 revcount = max(revcount, 1)
1258 tmpl.defaults['sessionvars']['revcount'] = revcount
1261 web.tmpl.defaults['sessionvars']['revcount'] = revcount
1259 1262 except ValueError:
1260 1263 pass
1261 1264
1262 lessvars = copy.copy(tmpl.defaults['sessionvars'])
1265 lessvars = copy.copy(web.tmpl.defaults['sessionvars'])
1263 1266 lessvars['revcount'] = max(revcount // 2, 1)
1264 morevars = copy.copy(tmpl.defaults['sessionvars'])
1267 morevars = copy.copy(web.tmpl.defaults['sessionvars'])
1265 1268 morevars['revcount'] = revcount * 2
1266 1269
1267 1270 graphtop = web.req.qsparams.get('graphtop', ctx.hex())
1268 graphvars = copy.copy(tmpl.defaults['sessionvars'])
1271 graphvars = copy.copy(web.tmpl.defaults['sessionvars'])
1269 1272 graphvars['graphtop'] = graphtop
1270 1273
1271 1274 count = len(web.repo)
General Comments 0
You need to be logged in to leave comments. Login now