GithubHelp home page GithubHelp logo

handlebars-cmd's Introduction

handlebars-cmd

Invoke handlebars from the commandline.

Example:

echo "Hello {{name}}" | handlebars --name Test

Output:

Hello Test

You may also pass a JSON string as an argument and it will be interpreted as an object.

You can also pass a JSON file:

handlebars file.json < template.hbs > output.txt

You can also do these:

handlebars file.json template.hbs

cat file.json | handlebars template.hbs

cat file.json | handlebars '{{name}}'

echo "{{sampleDate}}" | node ./index.js '{"sampleDate":"2016-12-01T08:00:54.194Z"}'

install

npm install -g handlebars-cmd

include helper

handlebars-cmd comes with a built-in helper #include

{{{include 'api.md'}}}

You can also pass context (optional)

{{{include 'render.md.hbs' item}}}

generic ES6 helpers

it also comes with str, math and date helpers 
built in (dirty and generic for now but usable for CLI purposes)


echo "Hello {{bd}} year {{date-getFullYear bd}}" | node ./index.js --name Test --bd "$(node -p "(new Date()).toJSON()")"	

echo "Hello {{str-substr name 1 2}}" | node index.js --name Test

echo "Hello {{math-min 10 2 12}}" | node index.js --name Test

dojo helpers

echo '{"sampleDate":"2016-12-01T08:00:54.194Z"}' | node ./index.js "{{dlocale-format sampleDate}}"

echo '{"sampleDate":"2016-12-01T08:00:54.194Z", "_fmt":{"formatLength":"long"}}' | node ./index.js "{{dlocale-format sampleDate _fmt}}"

echo '{"sampleDate":"2016-12-03T08:00:54.194Z"}' | node ./index.js "{{dlocale-isWeekend sampleDate}}"

echo '{"sampleDate":"2016-12-03T08:00:54.194Z"}' | node ./index.js "{{dlocale-isWeekend sampleDate}}"

TODO: dlocale-getNames sample

license

MIT

handlebars-cmd's People

Contributors

ainthek avatar spion avatar tonthanhhung avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

gratex

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.