Skip to content

Commit

Permalink
expose compile method to directly create templates and render them
Browse files Browse the repository at this point in the history
  • Loading branch information
defunctzombie committed Nov 4, 2011
1 parent 7231b51 commit 822cda6
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions index.js
Expand Up @@ -11,6 +11,24 @@ var jsrender = global.window.JsViews;
// export tag registration for users to provide custom tags
exports.registerTags = jsrender.views.registerTags;

// create a new template which you can invoke directly
// template(locals);
exports.compile = function(string) {

if (!string || typeof string !== "string") {
throw new Error('template must be a string');
}

// by using null, jsrender won't cache the object
// it will return the template compiled to us
var templ = jsrender.template( null, string );
return {
render: function(locals) {
return templ(locals);
}
};
}

// express view compiler
exports.express = {
compile: function (markup, options) {
Expand Down

0 comments on commit 822cda6

Please sign in to comment.