comparison hgext/highlight.py @ 6393:894875eae49b

hgweb: refactor hgweb code
author Dirkjan Ochtman <dirkjan@ochtman.nl>
date Fri, 28 Mar 2008 19:40:44 +0100
parents e75aab656f46
children 55bc0a035e1f
comparison
equal deleted inserted replaced
6392:2540521dc7c1 6393:894875eae49b
29 from mercurial import demandimport 29 from mercurial import demandimport
30 demandimport.ignore.extend(['pkgutil', 30 demandimport.ignore.extend(['pkgutil',
31 'pkg_resources', 31 'pkg_resources',
32 '__main__',]) 32 '__main__',])
33 33
34 from mercurial.hgweb.hgweb_mod import hgweb 34 from mercurial.hgweb import webcommands, webutil
35 from mercurial import util 35 from mercurial import util
36 from mercurial.templatefilters import filters 36 from mercurial.templatefilters import filters
37 37
38 from pygments import highlight 38 from pygments import highlight
39 from pygments.util import ClassNotFound 39 from pygments.util import ClassNotFound
77 77
78 oldl = tmpl.cache[field] 78 oldl = tmpl.cache[field]
79 newl = oldl.replace('line|escape', 'line|colorize') 79 newl = oldl.replace('line|escape', 'line|colorize')
80 tmpl.cache[field] = newl 80 tmpl.cache[field] = newl
81 81
82 def filerevision_highlight(self, tmpl, fctx): 82 web_filerevision = webcommands._filerevision
83 pygmentize(self, tmpl, fctx, 'fileline') 83 web_annotate = webcommands.annotate
84 84
85 return realrevision(self, tmpl, fctx) 85 def filerevision_highlight(web, tmpl, fctx):
86 pygmentize(web, tmpl, fctx, 'fileline')
87 return web_filerevision(web, tmpl, fctx)
86 88
87 def fileannotate_highlight(self, tmpl, fctx): 89 def annotate_highlight(web, req, tmpl):
88 pygmentize(self, tmpl, fctx, 'annotateline') 90 fctx = webutil.filectx(web.repo, req)
89 91 pygmentize(web, tmpl, fctx, 'annotateline')
90 return realannotate(self, tmpl, fctx) 92 return web_annotate(web, req, tmpl)
91 93
92 # monkeypatch in the new version 94 # monkeypatch in the new version
93 # should be safer than overriding the method in a derived class 95
94 # and then patching the class 96 webcommands._filerevision = filerevision_highlight
95 realrevision = hgweb.filerevision 97 webcommands.annotate = annotate_highlight
96 hgweb.filerevision = filerevision_highlight
97 realannotate = hgweb.fileannotate
98 hgweb.fileannotate = fileannotate_highlight