Skip to content
Browse files

return blank string when stache cant find partials neither in locals …

…nor file, instead of throw an exception.
  • Loading branch information...
1 parent c671533 commit 9ceab5ca000fa1fe1d5c9320efa32cca344a0f6b @mengxy mengxy committed Jun 27, 2011
Showing with 7 additions and 1 deletion.
  1. +7 −1 lib/stache.js
View
8 lib/stache.js
@@ -3,6 +3,7 @@
*/
var stache = {}
, fs = require('fs')
+ , path = require("path")
, mustache = require('mustache')
, views = '/';
@@ -21,7 +22,12 @@ stache.compile = function (source, options) {
var tag_replace_callback = function (match, operator, name) {
if (operator == '>' && !options.partials[name]) {
- return fs.readFileSync(views + '/' + name + (options.extension || '.mustache'), 'utf-8');
+ var partialFileName = views + '/' + name + (options.extension || '.mustache');
+ var partialContent = "";
+ if (path.existsSync(partialFileName)) {
+ partialContent = fs.readFileSync(partialFileName, 'utf-8');
+ }
+ return partialContent;
}
return match;
};

0 comments on commit 9ceab5c

Please sign in to comment.
Something went wrong with that request. Please try again.