Skip to content

Latest commit

 

History

History
116 lines (78 loc) · 4.01 KB

README.md

File metadata and controls

116 lines (78 loc) · 4.01 KB

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

  • key {String}: Either a key on a questions object on the context or a question to ask.
  • options {String}: Additional options to pass.
  • next {Function}: Callback function that will be passed an error and/or the results of asking the question.

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

  • template-helpers: Generic JavaScript helpers that can be used with any template engine. Handlebars, Lo-Dash, Underscore, or any engine that supports helper functions.
  • handlebars-helpers: 120+ Handlebars helpers in ~20 categories, for Assemble, YUI, Ghost or any Handlebars project. Includes helpers like {{i18}}, {{markdown}}, {{relative}}, {{extend}}, {{moment}}, and so on.
  • template: Render templates from any engine. Make custom template types, use layouts on pages, partials or any custom template type, custom delimiters, helpers, middleware, routes, loaders, and lots more. Powers Assemble v0.6.0, Verb v0.3.0 and your application.
  • engine-handlebars: Handlebars engine, consolidate.js style but with enhancements. This works with Assemble, express.js, engine-cache or any application that follows consolidate.js conventions.
  • engine-lodash: Lo-Dash engine, consolidate.js style but with enhancements. Works with Assemble, express.js, engine-cache or any application that follows consolidate.js conventions.

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.