puppy-api-docs
Version:
Genernate material api docs from your comments.
37 lines (33 loc) • 886 B
JavaScript
/**
* Helpers functions for handlebars.
*/
const helpers = {};
/**
* For each helper function for Handlebars
* @param {[Object]} Array of items to be looped over
* @param {Object} Block from within the template
*/
helpers.forEach = (items, block) => {
let accumulation = '';
for (let i = 0; i < items.length; i++) {
accumulation += block.fn(items[i]);
}
return accumulation;
};
/**
* Check if an object is undefined or not.
* @param {Object} item To be checked it undefined or not.
* @param {*} options Options provided by handlebars.
*/
helpers.notUndefined = (item, block) => {
console.log(this);
if (item !== undefined) {
return block.fn((String(item)));
} else {
return block.inverse((String(item)));
}
};
helpers.json = (item, options) => {
return JSON.stringify(item, null, 2);
};
module.exports = helpers;