From 65387a54688386532d7d3ec318df3cbef0e8e77e Mon Sep 17 00:00:00 2001 From: Phillip Johnsen Date: Mon, 9 Feb 2015 22:14:25 +0100 Subject: [PATCH] Created command line tool. CLI used to render a mustache template with a data view, writes the template into stdout when successfull. Otherwise meaningfull errors into stderr. Fixes #424 --- README.md | 30 ++++++++++++++ bin/mustache | 89 ++++++++++++++++++++++++++++++++++++++++ package.json | 3 ++ test/_files/cli.json | 3 ++ test/_files/cli.mustache | 1 + test/_files/cli.txt | 1 + test/cli-test.js | 70 +++++++++++++++++++++++++++++++ 7 files changed, 197 insertions(+) create mode 100755 bin/mustache create mode 100644 test/_files/cli.json create mode 100644 test/_files/cli.mustache create mode 100644 test/_files/cli.txt create mode 100644 test/cli-test.js diff --git a/README.md b/README.md index a41c5fa38..226074bee 100644 --- a/README.md +++ b/README.md @@ -461,6 +461,36 @@ These may be built using [Rake](http://rake.rubyforge.org/) and one of the follo $ rake yui3 $ rake qooxdoo +## Command line tool + +mustache.js is shipped with a node based command line tool. It might be installed as a global tool on your computer to render a mustache template of some kind + +```bash +$ npm install -g mustache +$ mustache dataView.json myTemplate.mustache > output.html + +# also supports stdin +$ cat dataView.json | mustache - myTemplate.mustache > output.html +``` + +or as a package.json `devDependency` in a build process maybe? + +```bash +$ npm install mustache --save-dev +``` +```json +{ + "scripts": { + "build": "mustache dataView.json myTemplate.mustache > public/output.html" + } +} +``` +```bash +$ npm run build +``` + +The command line tool is basically a wrapper around `Mustache.render` so you get all the aformentioned features. + ## Testing In order to run the tests you'll need to install [node](http://nodejs.org/). diff --git a/bin/mustache b/bin/mustache new file mode 100755 index 000000000..4b3f0c186 --- /dev/null +++ b/bin/mustache @@ -0,0 +1,89 @@ +#!/usr/bin/env node + +var fs = require('fs'); + +var Mustache = require('..'); +var pkg = require('../package'); + +var viewArg = process.argv[2]; +var templateArg = process.argv[3]; + +if (process.argv.indexOf('--version') > -1) { + return console.log(pkg.version); +} + +if (!templateArg || !viewArg) { + console.error('Syntax: mustache