Home

Awesome

question-helper NPM version Build Status

Helper used to ask questions and output the answer. Useful with Template, Handlebars, and Loadash.

Inspired by conversations with Jon Schlinkert

Install with npm

npm i question-helper --save

Usage

var question = require('question-helper');
var context = {questions: {name: "What's your name?"}};

// Prompt a user for a question and get an answer back.
question.call({ctx: context}, "name", function (err, answer) {
  if (err) return console.log('error', err);
  console.log('Answer', answer);
});

Params

Template

To use with template:

npm i template --save

Then add to your project.

var template = require('template');

handebars

Register handlebars as an engine:

template.engine('hbs', require('engine-handlebars'));

var question = require('question-helper');
var context = {questions: {name: "What's your name?"}};

template.page('author.hbs', "Author: {{question 'name'}}");
template.render('author.hbs', context, function (err, content) {
  if (err) return console.log('error', err);
  console.log(content);
});

Lo-Dash

Register Lo-Dash as an engine:

template.engine('html', require('engine-lodash'));

var context = {questions: {name: "What's your name?"}};
template.page('author.html', "Author: <%= question('name') %>");

template.render('author.html', context, function (err, content) {
  if (err) return console.log('error', err);
  console.log(content);
});

Running tests

Install dev dependencies.

npm i -d && npm test

Contributing

Pull requests and stars are always welcome. For bugs and feature requests, please create an issue

Related

Author

Brian Woodward

License

Copyright (c) 2015 Brian Woodward
Released under the MIT license


This file was generated by verb-cli on March 05, 2015.