How to use the handlebars.helpers 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 nuysoft / Mock / test / mock4xtpl.js View on Github external
{{#each items}}
  <li>{{agree_button}}</li>
  {{/each}}

        */
    })
    var ast = Handlebars.parse(tpl)
    // console.log(JSON.stringify(ast, null, 4));
    var result = Mock4Tpl.gen(ast, null, {
        'items|1-10': [{
                'id|+1': 1,
                name: '@FIRST @LAST',
                emotion: '@SENTENCE'
            }
        ]
    }, Handlebars.helpers)
    // console.log(JSON.stringify(result, null, 4))
    // console.log(Handlebars.helpers)

    test.ok(util.isArray(result.items))
    test.ok(result.items.length &gt;= 1 &amp;&amp; result.items.length &lt;= 10)
    test.ok(!('agree_button' in result.items[0]))
    test.ok('name' in result.items[0])
    test.ok('emotion' in result.items[0])
    test.done()
}
github mozilla / fxa-content-server / server / lib / i18n.js View on Github external
module.exports = function (config) {

  // this is perhaps a bit janky. In dev mode, a `t` helper needs to be
  // registered to render text in the static templates. Without the helper,
  // all {{#t}} surrounded text is empty.
  const handlebars = require('handlebars');
  // This file is used by both the build system and the server.
  // If part of the build system, `t` is already defined. Do not re-register
  // or else the static templates are not translated.
  if (! (handlebars.helpers && handlebars.helpers.t)) {
    handlebars.registerHelper('t', function (msg) {
      if (msg.fn) {
        return this.format(this.gettext(msg.fn(this)), this);
      }

      return this.format(this.gettext(msg), this);
    });
  }


  const abide = require('i18n-abide');

  // Configure i18n-abide for loading gettext templates.
  // This causes it to process the configuration settings, parse the
  // message files for each language, etc.
  //
github janrain / raml-fleece / src / to-html.js View on Github external
handlebars.registerHelper('showCodeOrForm', function(data, options) {
  var ret;
  if (data.type === 'application/x-www-form-urlencoded') {
    ret = handlebars.partials.parameters({
      type: 'Form',
      params: data.params,
    });
  } else {
    ret = handlebars.helpers.showCode(
      data.example,
      {hash: {type: data.type}}
    );
  }
  return new handlebars.SafeString(ret);
});
handlebars.registerHelper('showCode', function(data, options) {
github tom-grey / typedoc-plugin-markdown / src / lib / theme / helpers / breadcrumbs.ts View on Github external
function breadcrumb(model: Reflection, project: ProjectReflection, md: string[]) {
  if (model && model.parent) {
    breadcrumb(model.parent, project, md);
    if (model.url) {
      md.push(`[${model.name}](${Handlebars.helpers.relativeURL.call(this, model.url)})`);
    } else {
      md.push(model.url);
    }
  } else {
    md.push(`[Globals](${Handlebars.helpers.relativeURL.call(this, project.url)})`);
  }
  return md.join(' › ');
}
github ollm / OpenComic / scripts / opencomic.js View on Github external
$.each(arguments, function (i, arg) {

		if(hb.helpers[arg])
		{
			helpers.push(hb.helpers[arg]);
		}
		else
		{
			value = arg;

			$.each(helpers, function (j, helper) {
				value = helper(value, arguments[i + 1]);
			});

			return false;
		}
	});
github amekkawi / cwlogs-writable / .bin / docs / helpers.js View on Github external
var handlebars = require('handlebars');

if (!handlebars.helpers.inlineLinks) {
	throw new Error('inlineLinks helper not registered -- might not be the correct handlebars instance');
}

exports.linkPrefix = function() {
	return '';
};

exports.packageVersion = function() {
	return process.env.DOCS_PACKAGE_VERSION;
};

exports.typedef = function(options) {
	options.hash.kind = 'typedef';
	var result = handlebars.helpers._identifier(options);
	return result ? options.fn(result) : 'ERROR, Cannot find typedef.';
};
github abecms / abecms / src / cli / cms / templates / handlebars / removeRootPath.js View on Github external
export default function removeRootPath(obj, url, formater) {
  obj = JSON.parse(JSON.stringify(obj).replace(new RegExp(JSON.parse(url).root, 'g'), ''))
  obj = Handlebars.helpers[formater](obj)
	
  return obj
}
github future-architect / cheetah-grid / packages / docs / scripts / handlebars / helpers.js View on Github external
tree.push(category);
			const demo = allDemos.find((demo) =&gt; {
				const demoCategorys = Array.isArray(demo.category) ? demo.category : [demo.category];
				return arraysEqual([...demoCategorys, demo.title], tree);
			});
			if (!demo || !demo.path) {
				if (tree.length === 1) {
					const path = Handlebars.helpers.ms_path.call(
							this, Handlebars.helpers.ms_finalpath.call(this, './index.html', opt), opt
					);
					const hash = (`${category}`).toLowerCase().replace(/ /g, '-');
					return `<a href="${path}#${hash}">${category}</a>`;
				}
				return category;
			}
			const path = Handlebars.helpers.ms_path.call(
					this, Handlebars.helpers.ms_finalpath.call(this, demo.path, opt), opt
			);

			return `<a href="${path}">${category}</a>`;
		}).join(' &gt; ');
	});
github cliqz-oss / browser-core / modules / core / sources / templates.es View on Github external
Handlebars.registerHelper('timeOrCalculator', function(ezType) {
        if(ezType=="time") {
          return Handlebars.helpers.local("time");
        } else {
          return Handlebars.helpers.local("calculator");
        }
    });
github Radarr / Radarr / src / UI / Settings / CustomFormats / Edit / CustomFormatEditView.js View on Github external
tagClass : function(item) {
                var cls = "label ";
                var otherLabel = "label-" + Handlebars.helpers.formatTagLabelClass(item);
                return cls + otherLabel;
            }
        });