Procházet zdrojové kódy

Support .js views with functions in CLI (#717)

Fixes https://github.com/janl/mustache.js/issues/429
tags/v3.1.0
Justin Phillip Johnsen před 6 roky
rodič
revize
13cde0442e
4 změnil soubory, kde provedl 28 přidání a 5 odebrání
  1. +18
    -5
      bin/mustache
  2. +8
    -0
      test/_files/cli_js_view_with_function.js
  3. +1
    -0
      test/_files/cli_js_view_with_function.mustache
  4. +1
    -0
      test/_files/cli_js_view_with_function.txt

+ 18
- 5
bin/mustache Zobrazit soubor

@@ -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));
});
var view;
if (isJsFile(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) {
@@ -121,6 +130,10 @@ function isStdin (view) {
return view === '-';
}

function isJsFile (view) {
return path.extname(view) === '.js';
}

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


+ 8
- 0
test/_files/cli_js_view_with_function.js Zobrazit soubor

@@ -0,0 +1,8 @@
module.exports = {
'name': 'Tater',
'bold': function () {
return function (text, render) {
return '<b>' + render(text) + '</b>';
};
}
};

+ 1
- 0
test/_files/cli_js_view_with_function.mustache Zobrazit soubor

@@ -0,0 +1 @@
{{#bold}}Hi {{name}}.{{/bold}}

+ 1
- 0
test/_files/cli_js_view_with_function.txt Zobrazit soubor

@@ -0,0 +1 @@
<b>Hi Tater.</b>

Načítá se…
Zrušit
Uložit