Permalink
Browse files

Added support for Express.

  • Loading branch information...
1 parent 1ebdf3e commit 52dd4d8bc2466ca9b4471c8d9fe5dcd7898d73b4 Lorren Biffin committed Jun 30, 2011
Showing with 26 additions and 2 deletions.
  1. +26 −2 index.js
View
28 index.js
@@ -95,5 +95,29 @@ function fromString( string ){
return CACHE[hash] = createTemplate(string, hash);
}
-exports.fromFile = fromFile;
-exports.fromString = fromString;
+
+var nodet = require('node-t');
+
+module.exports = {
+ fromFile: fromFile,
+ fromString: fromString,
+ compile: function (source, options, callback) {
+ self = this;
+ if (typeof source == 'string') {
+ return function(options) {
+ options.locals = options.locals || {};
+ options.partials = options.partials || {};
+ if (options.body) // for express.js > v1.0
+ options.locals.body = options.body;
+ var tmpl = fromString(source);
+ return tmpl.render(options.locals);
+ };
+ } else {
+ return source;
+ }
+ },
+ render: function (template, options) {
+ template = this.compile(template, options);
+ return template(options);
+ }
+};

0 comments on commit 52dd4d8

Please sign in to comment.