Permalink
Browse files

added support to load files in Node.js

  • Loading branch information...
1 parent 95bd8ad commit 1628ee542198bb9194d22a85c6c4d6cc2deb8dd5 @darobin darobin committed with Jun 2, 2010
Showing with 18 additions and 1 deletion.
  1. +18 −1 lib/Template.js
View
@@ -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.