UNPKG

667 BJavaScriptView Raw
1'use strict';
2
3var _ = require('lodash');
4
5/**
6 * Is any value included in a collection or a string?
7 *
8 * @example
9 * {{#contains fonts "Roboto"}} ... {{/contains}}
10 * {{#contains font_path "Roboto"}} ... {{/contains}}
11 */
12function helper(paper) {
13 paper.handlebars.registerHelper('contains', function () {
14 var args = Array.prototype.slice.call(arguments, 0, -1),
15 options = _.last(arguments),
16 contained = _.contains.apply(_, args);
17
18 // Yield block if true
19 if (contained) {
20 return options.fn(this);
21 } else {
22 return options.inverse(this);
23 }
24 });
25}
26
27module.exports = helper;