Esempio n. 1
0
/**
  Uses HTMLBars `compile` function to process a string into a compiled template.

  This is not present in production builds.

  @private
  @method compile
  @param {String} templateString This is the string to be compiled by HTMLBars.
  @param {Object} options This is an options hash to augment the compiler options.
*/
export default function(templateString, options) {
  if (isEnabled('ember-glimmer')) {
    if (!compile && has('glimmer-compiler')) {
      compile = require('glimmer-compiler').compileSpec;
    }

    if (!compile) {
      throw new Error('Cannot call `compile` without the template compiler loaded. Please load `ember-template-compiler.js` prior to calling `compile`.');
    }

    return template(compile(templateString, compileOptions(options)));
  } else {
    if (!compile && has('htmlbars-compiler/compiler')) {
      compile = require('htmlbars-compiler/compiler').compile;
    }

    if (!compile) {
      throw new Error('Cannot call `compile` without the template compiler loaded. Please load `ember-template-compiler.js` prior to calling `compile`.');
    }

    var templateSpec = compile(templateString, compileOptions(options));

    return template(templateSpec);
  }
}
Esempio n. 2
0
QUnit.test('sets `isTop` on the provided function', function() {
  function test() { }

  var result = template(test);

  equal(result.isTop, true, 'sets isTop on the provided function');
});
Esempio n. 3
0
QUnit.test('sets `isMethod` on the provided function', function() {
  function test() { }

  var result = template(test);

  equal(result.isMethod, false, 'sets isMethod on the provided function');
});
Esempio n. 4
0
/**
  Uses HTMLBars `compile` function to process a string into a compiled template.

  This is not present in production builds.

  @private
  @method compile
  @param {String} templateString This is the string to be compiled by HTMLBars.
  @param {Object} options This is an options hash to augment the compiler options.
*/
export default function(templateString, options) {
  if (!compile && Ember.__loader.registry['htmlbars-compiler/compiler']) {
    compile = requireModule('htmlbars-compiler/compiler').compile;
  }

  if (!compile) {
    throw new Error('Cannot call `compile` without the template compiler loaded. Please load `ember-template-compiler.js` prior to calling `compile`.');
  }

  var templateSpec = compile(templateString, compileOptions(options));

  return template(templateSpec);
}
Esempio n. 5
0
test('should work with precompiled templates', function() {
  var templateString = precompile('{{view.value}}');
  var compiledTemplate = template(eval(templateString));

  view = EmberView.create({
    value: 'rendered',
    template: compiledTemplate
  });

  runAppend(view);

  equal(view.$().text(), 'rendered', 'the precompiled template was rendered');

  run(function() {
    view.set('value', 'updated');
  });

  equal(view.$().text(), 'updated', 'the precompiled template was updated');
});