Skip to content

Commit d18cb8e

Browse files
committed
Add render_string coroutine, make 0.4.0 release
1 parent 905cea0 commit d18cb8e

File tree

3 files changed

+36
-14
lines changed

3 files changed

+36
-14
lines changed

CHANGES.txt

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,20 @@
11
CHANGES
22
=======
33

4-
X.X.X (XXXX-XX-XX)
4+
0.4.0 (2015-04-02)
5+
------------------
6+
7+
- Add `render_string` method
8+
9+
0.3.1 (2015-04-01)
510
------------------
611

712
- Don't allow non-mapping context
813

14+
- Fix tiny documentation issues
15+
16+
- Change the library logo
17+
918
0.3.0 (2015-03-15)
1019
------------------
1120

aiohttp_jinja2/__init__.py

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from aiohttp import web
66

77

8-
__version__ = '0.3.1'
8+
__version__ = '0.4.0'
99

1010
__all__ = ('setup', 'get_env', 'render_template', 'template')
1111

@@ -23,8 +23,7 @@ def get_env(app, *, app_key=APP_KEY):
2323
return app.get(app_key)
2424

2525

26-
def _render_template(template_name, request, response, context, *,
27-
app_key, encoding):
26+
def render_string(template_name, request, context, *, app_key):
2827
env = request.app.get(app_key)
2928
if env is None:
3029
raise web.HTTPInternalServerError(
@@ -40,16 +39,16 @@ def _render_template(template_name, request, response, context, *,
4039
raise web.HTTPInternalServerError(
4140
text="context should be mapping, not {}".format(type(context)))
4241
text = template.render(context)
43-
response.content_type = 'text/html'
44-
response.charset = encoding
45-
response.text = text
42+
return text
4643

4744

4845
def render_template(template_name, request, context, *,
4946
app_key=APP_KEY, encoding='utf-8'):
5047
response = web.Response()
51-
_render_template(template_name, request, response, context,
52-
app_key=app_key, encoding=encoding)
48+
text = render_string(template_name, request, context, app_key=app_key)
49+
response.content_type = 'text/html'
50+
response.charset = encoding
51+
response.text = text
5352
return response
5453

5554

@@ -63,11 +62,10 @@ def wrapped(*args):
6362
coro = func
6463
else:
6564
coro = asyncio.coroutine(func)
66-
response = web.Response()
6765
context = yield from coro(*args)
6866
request = args[-1]
69-
_render_template(template_name, request, response, context,
70-
app_key=app_key, encoding=encoding)
67+
response = render_template(template_name, request, context,
68+
app_key=app_key, encoding=encoding)
7169
response.set_status(status)
7270
return response
7371
return wrapped

docs/index.rst

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,12 +79,27 @@ Reference
7979
by default.
8080

8181

82+
.. function:: render_string(template_name, request, context, *, \
83+
app_key=APP_KEY)
84+
85+
Return :class:`str` which contains template
86+
*template_name* filled with *context*.
87+
88+
*request* is a parameter from :term:`web-handler`,
89+
:class:`aiohttp.web.Request` instance.
90+
91+
*app_key* is an optional key for application dict, :const:`APP_KEY`
92+
by default.
93+
94+
8295
.. function:: render_template(template_name, request, context, *, \
8396
app_key=APP_KEY, encoding='utf-8')
8497

8598
Return :class:`aiohttp.web.Response` which contains template
86-
*template_name* filled with *context* and is a response to
87-
*request* (:class:`aiohttp.web.Request` instance).
99+
*template_name* filled with *context*.
100+
101+
*request* is a parameter from :term:`web-handler`,
102+
:class:`aiohttp.web.Request` instance.
88103

89104
*app_key* is an optional key for application dict, :const:`APP_KEY`
90105
by default.

0 commit comments

Comments
 (0)