From 4c88fe5a2efc7cc6a5412966aa44fb80f19415aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20=27Necoro=27=20Neumann?= Date: Mon, 3 May 2010 15:43:00 +0200 Subject: Change code to be run in a multiple-app env --- highlighting.py | 12 +++++------- index.py | 4 ++-- renderer.py | 3 ++- templates/root.mako | 2 -- 4 files changed, 9 insertions(+), 12 deletions(-) diff --git a/highlighting.py b/highlighting.py index f859920..439ae78 100644 --- a/highlighting.py +++ b/highlighting.py @@ -7,13 +7,11 @@ formatter = HtmlFormatter(encoding = "utf-8", classprefix="pygm", nowrap=True) BashLexer.tokens["basic"].append((r'\b(emerge|layman|git(?!:))\s*\b(?!\.)', Name.Builtin)) -def highlight(context, code, lang): +def highlight(code, lang): l = get_lexer_by_name(lang, encoding = "utf-8") - context.write(pygHighlight(code, l, formatter)) - return '' + return pygHighlight(code, l, formatter) -def get_css(context): - context.write("""""" % formatter.get_style_defs()) - return '' +""" % formatter.get_style_defs() diff --git a/index.py b/index.py index 5db7b25..b91418d 100755 --- a/index.py +++ b/index.py @@ -7,8 +7,8 @@ import controller # URL Mappings # urls = ( - "/r/(.*)", "controller.Redirect", - "/(.*)", "controller.Page" + "/r/(.*)", controller.Redirect, + "/(.*)", controller.Page ) # diff --git a/renderer.py b/renderer.py index 5e19a92..ba08e36 100644 --- a/renderer.py +++ b/renderer.py @@ -4,6 +4,7 @@ import mako from mako.lookup import TemplateLookup import helper +import highlighting class Renderer: """ @@ -23,7 +24,7 @@ class Renderer: except mako.exceptions.TopLevelLookupException, e: raise web.ctx.app_stack[-1].notfound(tpl) - return t.render(h = helper, url = helper.url, w = web, **kwargs) + return t.render(h = helper, url = helper.url, w = web, _hl = highlighting, **kwargs) __call__ = render diff --git a/templates/root.mako b/templates/root.mako index 72dac01..39ee098 100644 --- a/templates/root.mako +++ b/templates/root.mako @@ -38,8 +38,6 @@ ## functions -<%namespace name="_hl" module="highlighting"/> - <%def name="hl(lang)">
${_hl.highlight(capture(caller.body), lang)}
-- cgit v1.2.3