defunkt/pystache — Issue #52: Remove the context parameter from Template.__init__()
Author: cjerdonek
Created: 2011-12-17 21:20:59+00:00
State: open

Rather than passing the context to render to `Template.__init__()`:

template = Template(template, context, **kwargs)
rendered = template.render()

I think we should pass the context to render to `Template.render()`:

template = Template(template)
rendered = template.render(context, **kwargs)

This is conceptually clearer because the context to render is distinct from the template itself.

This also has at least a couple advantages from an API perspective:

(1) It lets you render multiple contexts with the same template:

template = Template(template)
rendered1 = template.render(context1)
rendered2 = template.render(context2)

(2) It also promotes a clean separation between Template options and the context **kwargs. For example, we could do this:

template = Template(template, **options)
rendered = template.render(context, **kwargs)

Passing both template options and context `**kwargs` to `Template.__init__()` leads to the situation where adding a new Template option as a keyword argument always breaks backwards compatiblity (by potentially conflicting with context `**kwargs` sharing the same name that are already out in the wild).