Exemple #1
0
export function content(morph, path, view, params, hash, options, env) {
  // TODO: just set escaped on the morph in HTMLBars
  morph.escaped = options.escaped;
  var helper = lookupHelper(path, view, env);
  if (!helper) {
    helper = lookupHelper('bindHelper', view, env);
    // Modify params to include the first word
    params.unshift(path);
    options.types = ['id'];
  }

  streamifyArgs(view, params, hash, options, env);
  sanitizeOptionsForHelper(options);
  return helper.call(view, params, hash, options, env);
}
test('returns undefined if no container exists (and helper is not found in env)', function() {
  var env = generateEnv();
  var view = {};

  var actual = lookupHelper('flubarb', view, env);

  equal(actual, undefined, 'does not blow up if view does not have a container');
});
test('looks for helpers in the provided `env.helpers`', function() {
  var env = generateEnv({
    'flubarb': function() { }
  });

  var actual = lookupHelper('flubarb', null, env);

  equal(actual, env.helpers.flubarb, 'helpers are looked up on env');
});
Exemple #4
0
export function component(morph, tagName, view, hash, options, env) {
  var params = [];
  var helper = lookupHelper(tagName, view, env);

  Ember.assert('You specified `' + tagName + '` in your template, but a component for `' + tagName + '` could not be found.', !!helper);

  streamifyArgs(view, params, hash, options, env);
  sanitizeOptionsForHelper(options);
  return helper.call(view, params, hash, options, env);
}
Exemple #5
0
export function subexpr(path, view, params, hash, options, env) {
  var helper = lookupHelper(path, view, env);

  if (helper) {
    streamifyArgs(view, params, hash, options, env);
    sanitizeOptionsForHelper(options);
    return helper.call(view, params, hash, options, env);
  } else {
    return view.getStream(path);
  }
}
Exemple #6
0
export function element(element, path, view, params, hash, options, env) { //jshint ignore:line
  var helper = lookupHelper(path, view, env);

  if (helper) {
    streamifyArgs(view, params, hash, options, env);
    sanitizeOptionsForHelper(options);
    return helper.call(view, params, hash, options, env);
  } else {
    return view.getStream(path);
  }
}
test('registers a helper in the container if component is found', function() {
  var env = generateEnv();
  var view = {
    container: generateContainer()
  };

  view.container.register('component:some-name', Component);

  lookupHelper('some-name', view, env);

  ok(view.container.lookup('helper:some-name'), 'new helper was registered');
});
test('does a lookup in the container if the name contains a dash (and helper is not found in env)', function() {
  var env = generateEnv();
  var view = {
    container: generateContainer()
  };

  function someName() {}
  view.container.register('helper:some-name', someName);

  var actual = lookupHelper('some-name', view, env);

  equal(actual, someName, 'does not blow up if view does not have a container');
});
test('does not lookup in the container if the name does not contain a dash (and helper is not found in env)', function() {
  var env = generateEnv();
  var view = {
    container: {
      lookup: function() {
        ok(false, 'should not lookup in the container');
      }
    }
  };

  var actual = lookupHelper('flubarb', view, env);

  equal(actual, undefined, 'does not blow up if view does not have a container');
});
 expectAssertion(function() {
   lookupHelper('some-name', view, env);
 }, 'Could not find \'component-lookup:main\' on the provided container, which is necessary for performing component lookups');
test('returns attribute when helper is `attribute`', function() {
  var actual = lookupHelper('attribute');

  equal(actual, attribute, 'attribute is a hard-coded helper');
});
test('returns concat when helper is `concat`', function() {
  var actual = lookupHelper('concat');

  equal(actual, concat, 'concat is a hard-coded helper');
});