Justin Phillip Johnsen 6 лет назад
Родитель
Сommit
13cde0442e
4 измененных файлов: 28 добавлений и 5 удалений
  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 Просмотреть файл

@@ -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 Просмотреть файл

@@ -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 Просмотреть файл

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

+ 1
- 0
test/_files/cli_js_view_with_function.txt Просмотреть файл

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

Загрузка…
Отмена
Сохранить