From e822dab9fdd09e6c0aa61adb4232e5fa783f355c Mon Sep 17 00:00:00 2001 From: Chris Wanstrath Date: Fri, 30 Oct 2009 10:38:00 -0700 Subject: [PATCH] kwargify pystache.render() --- pystache/__init__.py | 5 ++++- tests/test_pystache.py | 4 ++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/pystache/__init__.py b/pystache/__init__.py index f5caf36..5b22cca 100644 --- a/pystache/__init__.py +++ b/pystache/__init__.py @@ -1,4 +1,7 @@ from pystache.template import Template -def render(template, context={}): +def render(template, context={}, **kwargs): + context = context.copy() + for key in kwargs: + context[key] = kwargs[key] return Template(template, context).render() diff --git a/tests/test_pystache.py b/tests/test_pystache.py index fbcf3ca..097021a 100644 --- a/tests/test_pystache.py +++ b/tests/test_pystache.py @@ -6,6 +6,10 @@ class TestPystache(unittest.TestCase): ret = pystache.render("Hi {{thing}}!", { 'thing': 'world' }) self.assertEquals(ret, "Hi world!") + def test_kwargs(self): + ret = pystache.render("Hi {{thing}}!", thing='world') + self.assertEquals(ret, "Hi world!") + def test_less_basic(self): template = "It's a nice day for {{beverage}}, right {{person}}?" ret = pystache.render(template, { 'beverage': 'soda', 'person': 'Bob' })