Sha256: 566e3f9722bcf8cd6b89a3fd3e80e0d86bbbf8260ca2c44dce63523b7ee80d58

Contents?: true

Size: 1.52 KB

Versions: 3

Compression:

Stored size: 1.52 KB

Contents

/**
@module ember
*/
import compile from './compile';
/**
  Find templates stored in the head tag as script tags and make them available
  to `Ember.CoreView` in the global `Ember.TEMPLATES` object.

  Script tags with `text/x-handlebars` will be compiled
  with Ember's template compiler and are suitable for use as a view's template.

  @private
  @method bootstrap
  @for Ember.HTMLBars
  @static
  @param ctx
*/
function bootstrap({ context, hasTemplate, setTemplate }) {
    if (!context) {
        context = document;
    }
    let selector = 'script[type="text/x-handlebars"]';
    let elements = context.querySelectorAll(selector);
    for (let i = 0; i < elements.length; i++) {
        let script = elements[i];
        // Get the name of the script
        // First look for data-template-name attribute, then fall back to its
        // id if no name is found.
        let templateName = script.getAttribute('data-template-name') || script.getAttribute('id') || 'application';
        let template;
        template = compile(script.innerHTML, {
            moduleName: templateName,
        });
        // Check if template of same name already exists.
        if (hasTemplate(templateName)) {
            throw new Error(`Template named "${templateName}" already exists.`);
        }
        // For templates which have a name, we save them and then remove them from the DOM.
        setTemplate(templateName, template);
        // Remove script tag from DOM.
        script.parentNode.removeChild(script);
    }
}
export default bootstrap;

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
discourse-ember-source-3.6.0.0 dist/es/ember-template-compiler/lib/system/bootstrap.js
discourse-ember-source-3.5.1.1 dist/es/ember-template-compiler/lib/system/bootstrap.js
discourse-ember-source-3.5.1.0 dist/dist/es/ember-template-compiler/lib/system/bootstrap.js