jsantell/poet — pull request #50 by swijnands (2013-08-29 15:00:33+00:00)
Title: Asynchronous loading of templates

For our blog I really wanted to use pygmentize for syntax highlighting (in combination with marked).
However, pygmentize only supports asynchronous loading and poet's current templating method did not.

I changed the functionality so that when a second argument is present in a template function it will be considered as a node-style asynchronous callback (aka callback(err, result)).

For existing/default installations nothing has changed. So the new asynchronous callback style should definitely be opt-in only :)

Example async callback with markdown & pygmentize:
```javascript

var Poet = require('poet'),
marked = require('marked'),
pygmentize = require('pygmentize-bundled');

var poet = Poet(app, {
...
});

var markedOptions = {
...
highlight: function (code, lang, callback) {
pygmentize({ lang: lang, format: 'html' }, code, function (err, result) {
if (err) return callback(err);
callback(null, result.toString());
});
}
};

poet.addTemplate({
ext: ['md', 'markdown'],
fn: function (string, callback) { marked(string, markedOptions, callback); }
});

```