# railgun.templates

The tempaltes module contains a few functions that make it a bit easier to supply variable
data to arbitrary request or response fields in particular.  The template functions make
use of the excellent [Mustache](https://github.com/janl/mustache.js) templating library.
The functions exported by `railgun.templates` are essentially wrappers around Mustache.

## Module functions

### railgun.templates.fillGeneric

railgun.templates.fillGeneric is a very simple wrapper around `Mustache.render`. It
accepts two arguments: a string containing {{templates}} and an object mapping
template variables to the values they should take. The modified string is returned.

### railgun.templates.fillRequest

railgun.templates.fillRequest builds on `fillGeneric` to handle filling in templates
in the url, method, headers, and options of a request builder. It accepts three arguments,
with the third being optional.

1. A request builder object containing {{templates}} in any fields
2. An object containing keys that correspond to template variables to their values
3. An optional function that will call render on `request.options` values. See `examples/templated-requests.js`

`railgun.templates.fillRequest` returns the modified request builder.

### railgun.templates.fillResponse

railgun.templates.fillResponse is used to fill templates in a response builder object's `statusMessage`,
`statusCode`, `body`, and `headers`.  The `statusCode`, in particular, is parsed as an integer after
the template has been filled. The modified response builder is returned.
