Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

render(), closes #10

  • Loading branch information...
commit 79d1d918c4ecb02f787ea8a6341d26397db95b8a 1 parent b715701
Dag Odenhall authored
Showing with 17 additions and 1 deletion.
  1. +2 −0  docs/api.rst
  2. +11 −0 flaskext/genshi.py
  3. +4 −1 tests/rendering.py
2  docs/api.rst
View
@@ -7,6 +7,8 @@ API
Rendering functions
-------------------
+.. autofunction:: render
+
.. autofunction:: render_response
.. autofunction:: render_template
11 flaskext/genshi.py
View
@@ -281,3 +281,14 @@ def render_response(template=None, context=None,
mimetype = genshi.methods[method].get('mimetype', 'text/html')
template = render_template(template, context, method, string, filter)
return current_app.response_class(template, mimetype=mimetype)
+
+
+def render(template, **context):
+ """Render a template to a response object, passing the context as
+ keyword arguments. Shorthand for
+ ``render_response(template, dict(**context))``.
+
+ .. versionadded:: 0.6
+
+ """
+ return render_response(template, context)
5 tests/rendering.py
View
@@ -1,6 +1,6 @@
from __future__ import with_statement
from attest import Assert
-from flaskext.genshi import render_response
+from flaskext.genshi import render_response, render
from tests.utils import flask_tests
@@ -35,7 +35,10 @@ def renders_xml(context):
"""An xml extension results in no doctype and a application/xml mimetype"""
rendered = Assert(render_response('test.xml', context))
+ assert rendered.mimetype == 'application/xml'
+ assert rendered.data == '<name>Rudolf</name>'
+ rendered = Assert(render('test.xml', **context))
assert rendered.mimetype == 'application/xml'
assert rendered.data == '<name>Rudolf</name>'
Please sign in to comment.
Something went wrong with that request. Please try again.