Parcourir la source

Fixes #429 - support .js views with functions.

pull/717/head
Justin Staubach il y a 6 ans
Parent
révision
625d3cde24
1 fichiers modifiés avec 18 ajouts et 5 suppressions
  1. +18
    -5
      bin/mustache

+ 18
- 5
bin/mustache Voir le fichier

@@ -53,11 +53,20 @@ function run (/*args*/) {
} }


function readView (cb) { 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) { function parseView (str) {
@@ -121,6 +130,10 @@ function isStdin (view) {
return view === '-'; return view === '-';
} }


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

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


Chargement…
Annuler
Enregistrer