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' })