jaredhanson/locomotive — pull request #121 by RaphiePS (2013-12-15 02:15:27+00:00)
Title: Pass locals into custom response functions

Previously, it was a pain to respond to a request with JSON while using `respond`. The controller object is cyclical, so passing it into `JSON.stringify` fails. Furthermore, that doesn't filter underscores.

So, this simply passes properly-filtered locals into custom response functions. It could be used for all sorts of things that accept plain ol' JSON, but here's a simple example of responding with either HTML or JSON:

pagesController.main = function() {
var self = this;
this.title = 'Locomotive';
this.respond({
html: true,
json: function(locals) { self.res.json(locals); } // new magic
})
};

I've only tested manually, but I'd be happy to write up some tests!