audreyr/cookiecutter — pull request #291 by bollwyvl (2014-10-23 04:00:51+00:00)
Title: Interpret cookiecutter.json values as templates

A feature I have missed from yeoman and paste is the ability to have default values be driven off other default values, and update default values based on input a user has already provided. It seems much more responsive this way, especially if you start with a human-readable name and successively mangle it into various file and class names.

This 3-liner treats successive prompts for values as Jinja2 templates, rendered in the context of `cookiecutter_dict` up to that point. It requires no additional coding knowledge for a cookiecutter author, as they must know the Jinja syntax, anyway, but has the potential to make life significantly easier for end users.

Example:
```json
# cookiecutter.json
{
"project_name": "IPython Custom Widget",
"repo_name": "{{ project_name|replace(' ', '') }}",
"pkg_name": "{{ repo_name|lower }}"
}
```
Thus, if the user gives `My Excellent Project` as `project_name`, and then takes the defaults, `repo_name` will become `MyExcellentProject` and `pkg_name` will become `myexcellentproject`.

This relies on the OrderedDict behavior of the JSON parsing, but this seems like a reasonably good assumption.

This should be backwards compatible unless there is someone out there in the wild that is offering unrendered jinja template strings as default values, and then somehow double-renders them... or is generating jinja templates. Not sure if that is even possible. Seems like a stretch, and could be achieved by using a `{%raw%}` block inside a value.

I haven't updated any docs, and would look for input as to whether this would be README material, Advanced Usage or otherwise.