Mercurial > genshi > genshi-test
diff examples/tutorial/geddit/lib/template.py @ 615:0dc152d128f5
GenshiTutorial: make URLs dynamic so that the app could theoretically be mounted on some other SCRIPT_NAME.
author | cmlenz |
---|---|
date | Wed, 29 Aug 2007 20:12:54 +0000 |
parents | 16b1be35c265 |
children | dba522b4c31d |
line wrap: on
line diff
--- a/examples/tutorial/geddit/lib/template.py +++ b/examples/tutorial/geddit/lib/template.py @@ -3,14 +3,14 @@ import cherrypy from genshi.core import Stream from genshi.output import encode, get_serializer -from genshi.template import TemplateLoader +from genshi.template import Context, TemplateLoader loader = TemplateLoader( os.path.join(os.path.dirname(__file__), '..', 'templates'), auto_reload=True ) -def output(filename, method=None, encoding='utf-8', **options): +def output(filename, method='html', encoding='utf-8', **options): """Decorator for exposed methods to specify what template the should use for rendering, and which serialization method and options should be applied. @@ -18,6 +18,8 @@ def decorate(func): def wrapper(*args, **kwargs): cherrypy.thread_data.template = loader.load(filename) + if method == 'html': + options.setdefault('doctype', 'html') serializer = get_serializer(method, **options) stream = func(*args, **kwargs) if not isinstance(stream, Stream): @@ -37,4 +39,6 @@ template = loader.load(args[0]) else: template = cherrypy.thread_data.template - return template.generate(**kwargs) + ctxt = Context(url=cherrypy.url) + ctxt.push(kwargs) + return template.generate(ctxt)