How to use the handlebars.createFrame function in handlebars

To help you get started, we’ve selected a few handlebars examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github hegemonic / jsdoc-baseline / lib / helpers / block / index.js View on Github external
eachIndexGroup(items, options) {
            const data = handlebars.createFrame(options.data || {});
            const indexGroups = {};
            // doclet kinds that always get their own section
            const sectionKinds = [
                'class',
                'interface',
                'module',
                'namespace'
            ];

            function findNameKey({doclet, longname}) {
                let previousMemberof;
                const shortened = {
                    previous: null,
                    current: null,
                    next: null
                };
github nuysoft / Mock / test / nodeunit / mock4tpl-node.js View on Github external
Handlebars.registerHelper('list', function(context, options) {
        var out = "<ul>",
            data;

        for (var i = 0; i &lt; context.length; i++) {
            if (options.data) {
                data = Handlebars.createFrame(options.data || {});
                data.index = i;
            }

            out += "<li>" + options.fn(context[i], {
                data: data
            }) + "</li>";
        }

        out += "</ul>";
        return out;
    });
github zordius / HandlebarsCookbook / helpers.js View on Github external
data.forEach(function (D, I) {
            var Data = handlebars.createFrame(options.data)

            Data.refs = refs

            if (I > 0) {
                Data.page_prev = data[I - 1]
            }
            if (data[I + 1] !== undefined) {
                Data.page_next = data[I + 1]
            }

            console.log('>> Writing the page:' + D.pagename)
            fs.writeFileSync(options.data.configs.out_dir + D.pagename + '.html', options.fn(D, {data: Data}))
        })
    },
github thumbsup / thumbsup / src / website / theme-base / helpers / times.js View on Github external
module.exports = function (n, block) {
  var accum = ''
  const data = require('handlebars').createFrame({})
  for (var i = 0; i &lt; n; ++i) {
    data.index = i
    accum += block.fn(this, { data: data })
  }
  return accum
}
github MyScienceWork / PolarisOS / app / modules / utils / templating.js View on Github external
Handlebars.registerHelper('people_join', (array, options) =&gt; {
    const hash = options.hash;
    const sep = hash.sep || ', ';
    const use_and = hash.useAnd || true;
    const minimal_number = hash.minNumber || 3;

    let data = {};
    if (options.data) {
        data = Handlebars.createFrame(options.data);
    }

    if (array.length &lt;= minimal_number) {
        if (array.length === 1) {
            return array.map((item, i) =&gt; { data.index = i; return options.fn(item, { data }); }).join(sep);
        }

        if (use_and) {
            const display = array.slice(0, array.length - 1);
            const separated = display.map((item, i) =&gt; { data.index = i; return options.fn(item, { data }); }).join(sep);
            data.index = array.length - 1;
            return `${separated} #POS#LANGl_and ${options.fn(array[array.length - 1], { data })}`;
        }
        return array.map((item, i) =&gt; { data.index = i; return options.fn(item, { data }); }).join(sep);
    }
    const display = array.slice(0, minimal_number);
github foundation / panini / helpers / repeat.js View on Github external
module.exports = function(count, options) {
  var str = '';
  var data;

  if (options.data) {
    data = Handlebars.createFrame(options.data);
  }

  for (var i = 0; i &lt; count; i++) {
    if (data) {
      data.index = i;
    }

    str += options.fn(this, { data: data });
  }

  return str;
}
github gloriajs / gloria / lib / build / handlebars-helpers.js View on Github external
Handlebars.registerHelper('eachWithSort', (array, key, direction, opts) =&gt; {
    let data;
    if (opts.data) {
        data  = Handlebars.createFrame(opts.data);
    }

    const sorted = array.sort((a, b) =&gt; {
        a = a[key];
        b = b[key];
        if (direction === '-') {
            return a &lt; b ? 1 : a == b ? 0 : -1;

        } else {
            return a &gt; b ? 1 : a == b ? 0 : -1;

        }

    });

    let s = '';
github zordius / HandlebarsCookbook / helpers.js View on Github external
set: function (name, value, options) {
        var data = handlebars.createFrame(options.data)

        data[name] = value

        return options.fn(this, {data: data})
    },
github zordius / HandlebarsCookbook / helpers.js View on Github external
render: function (options) {
        var data = handlebars.createFrame(options.data)

        if (data.standard && data.standard.type === (this.type || options.hash.type)) {
            Object.assign(data, data.standard)
        } else {
            Object.assign(data, helpers.data_for_render(this, options))
        }

        return options.fn(this, {data: data})
    },
github hegemonic / jsdoc-baseline / lib / helpers / block / index.js View on Github external
withOnly(options) {
            const context = handlebars.createFrame(options.hash);

            return options.fn(context);
        }
    };