diff --git a/bin/mustache b/bin/mustache index 430e8b937..2b2250a25 100755 --- a/bin/mustache +++ b/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'; } diff --git a/test/_files/cli_js_view_with_function.js b/test/_files/cli_js_view_with_function.js new file mode 100644 index 000000000..29d1a2766 --- /dev/null +++ b/test/_files/cli_js_view_with_function.js @@ -0,0 +1,8 @@ +module.exports = { + 'name': 'Tater', + 'bold': function () { + return function (text, render) { + return '' + render(text) + ''; + }; + } +}; \ No newline at end of file diff --git a/test/_files/cli_js_view_with_function.mustache b/test/_files/cli_js_view_with_function.mustache new file mode 100644 index 000000000..a73ebbe6a --- /dev/null +++ b/test/_files/cli_js_view_with_function.mustache @@ -0,0 +1 @@ +{{#bold}}Hi {{name}}.{{/bold}} \ No newline at end of file diff --git a/test/_files/cli_js_view_with_function.txt b/test/_files/cli_js_view_with_function.txt new file mode 100644 index 000000000..3f6eb97b7 --- /dev/null +++ b/test/_files/cli_js_view_with_function.txt @@ -0,0 +1 @@ +Hi Tater. \ No newline at end of file