Exemple #1
0
function appendInlineConditional(view, inverted, helperName, params) {
  Ember.assert(
    "The inline form of the `if` and `unless` helpers expect two or " +
    "three arguments, e.g. `{{if trialExpired 'Expired' expiryDate}}` " +
    "or `{{unless isFirstLogin 'Welcome back!'}}`.",
    params.length === 2 || params.length === 3
  );

  return conditional(
    shouldDisplay(params[0]),
    inverted ? params[2] : params[1],
    inverted ? params[1] : params[2]
  );
}
Exemple #2
0
/**
  See [boundIf](/api/classes/Ember.Handlebars.helpers.html#method_boundIf)
  and [unboundIf](/api/classes/Ember.Handlebars.helpers.html#method_unboundIf)

  @method if
  @for Ember.Handlebars.helpers
  @param {Function} context
  @param {Hash} options
  @return {String} HTML string
*/
function ifHelper(params, hash, options, env) {
  Ember.assert("If helper in block form expect exactly one argument", !options.template || params.length === 1);
  if (Ember.FEATURES.isEnabled('ember-htmlbars-inline-if-helper')) {
    if (!options.template) {
      _inlineIfAssertion(params);
      var condition = params[0];
      var truthy = params[1];
      var falsy = params[2];
      return conditional(shouldDisplay(condition), truthy, falsy);
    }
  }

  options.inverse = options.inverse || emptyTemplate;

  options.helperName = options.helperName || ('if ');

  if (env.data.isUnbound) {
    env.data.isUnbound = false;
    return env.helpers.unboundIf.helperFunction.call(this, params, hash, options, env);
  } else {
    return env.helpers.boundIf.helperFunction.call(this, params, hash, options, env);
  }
}