X-Git-Url: https://git.stderr.nl/gitweb?a=blobdiff_plain;f=plugin%2Ftheme%2Fsite.py;h=c2e1659eb6dd4b155bd1769b050244319d15fea0;hb=ec5754fc4e62f7603fdbd2dfdf827bd8f8d5dd7a;hp=17f4bfe3125c92fde5c203c93e3b85c6c49490f2;hpb=bca7a535d5c77b71a60e5f535db8b6f8116ca698;p=matthijs%2Fprojects%2Fwipi.git diff --git a/plugin/theme/site.py b/plugin/theme/site.py index 17f4bfe..c2e1659 100644 --- a/plugin/theme/site.py +++ b/plugin/theme/site.py @@ -1,6 +1,9 @@ # -*- coding: iso-8859-1 -*- """ - Evolution Events, website theme + MoinMoin - Generic website theme. + + @copyright: 2009+ Matthijs Kooijman + @license: GNU GPL, see COPYING for details. This theme is meant for wiki's that are meant to function as a website, meaning nothing fancy and wiki-ish (at least when you're not logged in). @@ -12,6 +15,7 @@ from MoinMoin.theme import ThemeBase from MoinMoin.Page import Page from MoinMoin import wikiutil +from StringIO import StringIO class SiteTheme(ThemeBase): @@ -46,8 +50,8 @@ class SiteTheme(ThemeBase): # Header u'' - #html += ThemeBase.endPage(self) + html = u'\n' + html += ThemeBase.endPage(self) + # This adds #pagebottom and closes #page return html -def execute(request): +def parse_wiki_page(request, page): """ - Generate and return a theme object - - @param request: the request object - @rtype: MoinTheme - @return: Theme object + This is an ugly hack to render a page into a string. By default, + formatters render using request.write automatically, which prevents us + from capturing the output. By disguising a StringIO buffer as a request + object, we manage to get at the rendered contents. + + However, when {{{#!wiki or similar blocks are used, stuff breaks (since + that creates a second parser that doesn't get our StringIO buffer). """ - return Theme(request) + Parser = wikiutil.searchAndImportPlugin(request.cfg, "parser", 'wiki') + # Create a stringIO buffer, to capture the output + buffer = StringIO() + # Make the buffer look like the request, since the parser writes + # directly to the request + buffer.form = request.form + buffer.getText = request.getText + buffer.cfg = request.cfg + # Create a new formatter. Since we need to set its page, we can't use + # request.formatter. + from MoinMoin.formatter.text_html import Formatter + formatter = Formatter(request) + formatter.setPage(page) + + # Create the parser and parse the page + parser = Parser(page.data, buffer) + parser.format(formatter) + # Return the captured buffer + return buffer.getvalue() # vim: set sw=4 sts=4 expandtab: