How to use the handlebars.Utils 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 discourse / discourse-data-explorer / assets / javascripts / discourse / components / query-row-content.js.es6 View on Github external
function category_badge_replacement(str, ctx) {
  const category = Ember.get(ctx.contexts[0], str);
  return categoryLinkHTML(category, {
    allowUncategorized: true,
  });
}

function bound_date_replacement(str, ctx) {
  const value = Ember.get(ctx.contexts[0], str);
  return new Handlebars.SafeString(
    autoUpdatingRelativeAge(new Date(value), { title: true })
  );
}

const esc = Handlebars.Utils.escapeExpression;

// consider moving this elsewhere
function guessUrl(t) {
  let [dest, name] = [t, t];

  const split = t.split(/,(.+)/);

  if (split.length > 1) {
    name = split[0];
    dest = split[1];
  }

  return [dest, name];
}

const QueryRowContentComponent = Ember.Component.extend({
github webroo / dummy-json / lib / helpers.js View on Github external
var data;
    var i;

    if (arguments.length === 3) {
      // If given two numbers then pick a random one between the two
      total = utils.randomInt(min, max);
    } else if (arguments.length === 2) {
      // If given one number then just use it as a fixed repeat total
      options = max;
      total = min;
    } else {
      throw new Error('The repeat helper requires a numeric param');
    }

    // Create a shallow copy of data so we can add variables without modifying the original
    data = Handlebars.Utils.extend({}, options.data);

    for (i = 0; i < total; i++) {
      // Clear the linked values on each iteration so a new set of names/companies is generated
      options.data.root.__cache = {};

      // You can access these in your template using @index, @total, @first, @last
      data.index = i;
      data.total = total;
      data.first = i === 0;
      data.last = i === total - 1;

      // By using 'this' as the context the repeat block will inherit the current scope
      ret = ret + options.fn(this, {data: data});

      if (options.hash.comma !== false) {
        // Trim any whitespace left by handlebars and add a comma if it doesn't already exist,
github webroo / dummy-json / index.js View on Github external
parse: function (string, options) {
    options = options || {};

    // Merge custom mockdata/helpers into the defaults, items with the same name will override
    options.mockdata = Handlebars.Utils.extend({}, mockdata, options.mockdata);
    options.helpers = Handlebars.Utils.extend({}, helpers, options.helpers);

    // If a seed is passed in the options it will override the default one
    utils.setRandomSeed(options.seed || dummyjson.seed);

    // Certain helpers, such as name and email, attempt to synchronise and use the same values when
    // called after one-another. This object acts as a cache so the helpers can share their values.
    options.mockdata.__cache = {};

    return Handlebars.compile(string)(options.mockdata, {
      helpers: options.helpers,
      partials: options.partials
    });
  },
github etsy / 411 / htdocs / assets / js / views / renderer / ip.js View on Github external
preview: function(key, val) {
            var url = 'https://freegeoip.net/?q=' + val;
            return [
                '<a href="',
                Handlebars.Utils.escapeExpression(url),
                '" rel="noreferrer">',
                Handlebars.Utils.escapeExpression(val),
                '</a>'
            ].join('');
        },
        render: function(key, val, data) {
github camelaissani / loca / frontend / js / lib / helper.js View on Github external
Handlebars.registerHelper('formatMonth', function(text/*, options*/) {
    text = Handlebars.Utils.escapeExpression(text);
    text = Helper.formatMonth(text);
    return new Handlebars.SafeString(text);
});
Handlebars.registerHelper('formatMonthYear', function(params) {
github apache / ranger / security-admin / src / main / webapp / templates / helpers / XAHelpers.js View on Github external
HHelpers.nl2br = function(text) {
        text = Handlebars.Utils.escapeExpression(text);
        var nl2br = (text + '').replace(/([^&gt;\r\n]?)(\r\n|\n\r|\r|\n)/g, '$1' + '<br>' + '$2');
        return new Handlebars.SafeString(nl2br);
    };
	Handlebars.registerHelper('nl2br', HHelpers.nl2br);
github vitalets / x-editable / generator / helpers.js View on Github external
Handlebars.registerHelper('source', function(options) {
  var out = '<pre class="prettyprint linenums">' + (Handlebars.Utils.escapeExpression(options.fn(this))).trim() + '</pre>';
  return new Handlebars.SafeString(out);
});
github jsperf / jsperf.com / templates / helpers / formatAuthor.js View on Github external
module.exports = function (name, url, isComment) {
  name = Handlebars.Utils.escapeExpression(name);
  url = Handlebars.Utils.escapeExpression(url);

  var str = '';

  if (name !== '') {
    if (isComment === undefined) {
      isComment = false;
    }

    if (!isComment) {
      str += 'by ';
    }

    if (url &amp;&amp; url !== '') {
      str += "<a name="" rel="nofollow" href="&quot; + url + &quot;">';</a>
github mtharrison / hapi.js-in-action / CH03 - Building a Website / 3.4 / 3.4.3 / views / helpers / breaklines.js View on Github external
module.exports = function (text) {

    text = Handlebars.Utils.escapeExpression(text);
    text = text.replace(/(\r\n|\n|\r)/gm, '<br>');
    return new Handlebars.SafeString(text);
};
github babel / website / bin / build-template.js View on Github external
Handlebars.registerHelper("list_link", function(text, url) {
  text = Handlebars.Utils.escapeExpression(text);
  url  = Handlebars.Utils.escapeExpression(url);

  var result = "' + text + "";

  return new Handlebars.SafeString(result);
});