Skip to content

Commit

Permalink
Fixes janl#429 - support .js views with functions.
Browse files Browse the repository at this point in the history
  • Loading branch information
JEStaubach committed Sep 5, 2019
1 parent 96cb5ef commit 625d3cd
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions bin/mustache
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,20 @@ function run (/*args*/) {
}

function readView (cb) {
var view = isStdin(viewArg) ? process.openStdin() : fs.createReadStream(viewArg);

streamToStr(view, function onDone (str) {
cb(parseView(str));
});
let view;
if (isJson(viewArg)) {
view = require(path.join(process.cwd(),viewArg));
cb(view);
} else {
if (isStdin(viewArg)) {
view = process.openStdin();
} else {
view = fs.createReadStream(viewArg);
}
streamToStr(view, function onDone (str) {
cb(parseView(str));
});
}
}

function parseView (str) {
Expand Down Expand Up @@ -121,6 +130,10 @@ function isStdin (view) {
return view === '-';
}

function isJson (view) {
return path.parse(view).ext === '.js';
}

function wasNotFound (err) {
return err.code && err.code === 'ENOENT';
}
Expand Down

0 comments on commit 625d3cd

Please sign in to comment.