Permalink
Browse files

added support to load files in Node.js

  • Loading branch information...
darobin authored and ashb committed Jun 2, 2010
1 parent 95bd8ad commit 1628ee542198bb9194d22a85c6c4d6cc2deb8dd5
Showing with 18 additions and 1 deletion.
  1. +18 −1 lib/Template.js
@@ -689,7 +689,24 @@ try {
return f.readWhole();
}
}
} catch (e) {}
} catch (e) {
// try Node.js
try {
var fs = require("fs");
if (typeof fs != "undefined" && "readFileSync" in fs) {
Template.Context.prototype.load_file = function load_file (file) {
var f;
try {
return fs.readFileSync(file);
}
catch (e) {
throw new Template.Exception("file", Template.escapeString(file) + ": not found");
}
};
}
}
catch (e) {}
}

Template.Parser = function (config) {
this.end_tag = this.default_end_tag;

0 comments on commit 1628ee5

Please sign in to comment.