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