Skip to content

Instantly share code, notes, and snippets.

@jrburke
Created February 3, 2012 18:40
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jrburke/1731666 to your computer and use it in GitHub Desktop.
Save jrburke/1731666 to your computer and use it in GitHub Desktop.
kumascript with promises
//based on:
//https://github.com/lmorchard/kumascript/blob/master/lib/kumascript/templates.js
var q = require('q');
var EJSTemplate = ks_utils.Class(BaseTemplate, {
initialize: function (options) {
this._super('initialize', arguments);
this.template = require('ejs').compile(this.options.source);
},
execute: function (args) {
var d = q.defer(),
vm = require("vm"),
ctx = {
"arguments": args
};
//q.call starts off a chain of async actions.
//Assumes below that this.template() returns a promise
q.call(function () {
return this.template(ctx);
}.bind(this))
.then(function (result) {
return result.trim();
})
.then(d.resolve, d.reject);
return d.promise;
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment