comparison hgext/highlight/__init__.py @ 7216:292fb2ad2846

extensions: use new wrapper functions
author Matt Mackall <mpm@selenic.com>
date Wed, 22 Oct 2008 17:34:52 -0500
parents 9df67ee30ef5
children 7fc30044b514
comparison
equal deleted inserted replaced
7215:0ab5f21c390b 7216:292fb2ad2846
18 -- Adam Hupp <adam@hupp.org> 18 -- Adam Hupp <adam@hupp.org>
19 """ 19 """
20 20
21 import highlight 21 import highlight
22 from mercurial.hgweb import webcommands, webutil, common 22 from mercurial.hgweb import webcommands, webutil, common
23 from mercurial import extensions
23 24
24 web_filerevision = webcommands._filerevision 25 def filerevision_highlight(orig, web, tmpl, fctx):
25 web_annotate = webcommands.annotate
26
27 def filerevision_highlight(web, tmpl, fctx):
28 mt = ''.join(tmpl('mimetype', encoding=web.encoding)) 26 mt = ''.join(tmpl('mimetype', encoding=web.encoding))
29 # only pygmentize for mimetype containing 'html' so we both match 27 # only pygmentize for mimetype containing 'html' so we both match
30 # 'text/html' and possibly 'application/xhtml+xml' in the future 28 # 'text/html' and possibly 'application/xhtml+xml' in the future
31 # so that we don't have to touch the extension when the mimetype 29 # so that we don't have to touch the extension when the mimetype
32 # for a template changes; also hgweb optimizes the case that a 30 # for a template changes; also hgweb optimizes the case that a
34 # can't clash with the file's content-type here in case we 32 # can't clash with the file's content-type here in case we
35 # pygmentize a html file 33 # pygmentize a html file
36 if 'html' in mt: 34 if 'html' in mt:
37 style = web.config('web', 'pygments_style', 'colorful') 35 style = web.config('web', 'pygments_style', 'colorful')
38 highlight.pygmentize('fileline', fctx, style, tmpl) 36 highlight.pygmentize('fileline', fctx, style, tmpl)
39 return web_filerevision(web, tmpl, fctx) 37 return orig(web, tmpl, fctx)
40 38
41 def annotate_highlight(web, req, tmpl): 39 def annotate_highlight(orig, web, req, tmpl):
42 mt = ''.join(tmpl('mimetype', encoding=web.encoding)) 40 mt = ''.join(tmpl('mimetype', encoding=web.encoding))
43 if 'html' in mt: 41 if 'html' in mt:
44 fctx = webutil.filectx(web.repo, req) 42 fctx = webutil.filectx(web.repo, req)
45 style = web.config('web', 'pygments_style', 'colorful') 43 style = web.config('web', 'pygments_style', 'colorful')
46 highlight.pygmentize('annotateline', fctx, style, tmpl) 44 highlight.pygmentize('annotateline', fctx, style, tmpl)
47 return web_annotate(web, req, tmpl) 45 return orig(web, req, tmpl)
48 46
49 def generate_css(web, req, tmpl): 47 def generate_css(web, req, tmpl):
50 pg_style = web.config('web', 'pygments_style', 'colorful') 48 pg_style = web.config('web', 'pygments_style', 'colorful')
51 fmter = highlight.HtmlFormatter(style = pg_style) 49 fmter = highlight.HtmlFormatter(style = pg_style)
52 req.respond(common.HTTP_OK, 'text/css') 50 req.respond(common.HTTP_OK, 'text/css')
53 return ['/* pygments_style = %s */\n\n' % pg_style, fmter.get_style_defs('')] 51 return ['/* pygments_style = %s */\n\n' % pg_style, fmter.get_style_defs('')]
54 52
55
56 # monkeypatch in the new version 53 # monkeypatch in the new version
57 54 extensions.wrapfunction(webcommands, '_filerevision', filerevision_highlight)
58 webcommands._filerevision = filerevision_highlight 55 extensions.wrapfunction(webcommands, 'annotate', annotate_highlight)
59 webcommands.annotate = annotate_highlight
60 webcommands.highlightcss = generate_css 56 webcommands.highlightcss = generate_css
61 webcommands.__all__.append('highlightcss') 57 webcommands.__all__.append('highlightcss')