Skip to content

Commit

Permalink
added support to load files in Node.js
Browse files Browse the repository at this point in the history
  • Loading branch information
darobin authored and ashb committed Jun 15, 2010
1 parent 95bd8ad commit 1628ee5
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion lib/Template.js
Expand Up @@ -689,7 +689,24 @@ try {
return f.readWhole(); 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) { Template.Parser = function (config) {
this.end_tag = this.default_end_tag; this.end_tag = this.default_end_tag;
Expand Down

0 comments on commit 1628ee5

Please sign in to comment.