All Downloads are FREE. Search and download functionalities are using the official Maven repository.

nack.handlebars.4.4.0.source-code.helpers.nashorn.js Maven / Gradle / Ivy

The newest version!
/**
 * The Handlebars global variable.
 */
var Handlebars = {};
/**
 * Helpers
 */
Handlebars.helpers = {};

/**
 * Creates Handlebars.SafeString
 */
Handlebars.SafeString = Java.type('com.github.jknack.handlebars.Handlebars.SafeString');

/**
 * Creates Handlebars.Utils
 */
Handlebars.Utils = Java.type('com.github.jknack.handlebars.Handlebars.Utils');
Handlebars.escapeExpression = Handlebars.Utils.escapeExpression;

/**
 * Register helper function.
 *
 * @param {String} name The helper's name. Required.
 * @param {Function} helper The helper function. Required.
 */
Handlebars.registerHelper = function (name, helper) {
  /**
   * Bridge between a Java and JavaScript helpers.
   */
  var fn = function (context, options) {
    var args = [];
    var self = options.context.model();
    var psize = options.context.data('com.github.jknack.handlebars.Context#paramSize')
    if (psize > 0) {
      args.push(context);
      for(var i = 0; i < options.params.length; i++) {
        args.push(options.params[i]);
      }
    }
    args.push(options);

    // Invoke the JavaScript helper.
    return helper.apply(self, args);
  };

  Handlebars.helpers[name] = helper;
  Handlebars_java.registerHelper(name, fn);
};




© 2015 - 2024 Weber Informatics LLC | Privacy Policy