diff --git a/app-lt-2-9/instance-initializers/browser/head.js b/app-lt-2-9/instance-initializers/browser/head.js new file mode 100644 index 0000000..1080249 --- /dev/null +++ b/app-lt-2-9/instance-initializers/browser/head.js @@ -0,0 +1,21 @@ +import Ember from 'ember'; +import ENV from '../../config/environment'; + +export function initialize(instance) { + if (ENV['ember-cli-head'] && ENV['ember-cli-head']['suppressBrowserRender']) { return true; } + + // clear fast booted head (if any) + Ember.$('meta[name="ember-cli-head-start"]') + .nextUntil('meta[name="ember-cli-head-end"] ~') + .addBack() + .remove(); + const container = instance.lookup ? instance : instance.container; + // const renderer = container.lookup('renderer:-dom'); + const component = container.lookup('component:head-layout'); + component.appendTo(document.head); +} + +export default { + name: 'head-browser', + initialize: initialize +}; diff --git a/app-lt-2-9/instance-initializers/fastboot/head.js b/app-lt-2-9/instance-initializers/fastboot/head.js new file mode 100644 index 0000000..8ef6b54 --- /dev/null +++ b/app-lt-2-9/instance-initializers/fastboot/head.js @@ -0,0 +1,19 @@ +export function initialize(instance) { + const renderer = instance.lookup('renderer:-dom'); + const componentFactory = + instance._lookupFactory('component:head-layout'); + // explicitly set renderer & domhelper since we're in fastboot + const component = componentFactory.create( + instance.ownerInjection(), + { + renderer, + _domHelper: renderer._dom + } + ); + component.appendTo(renderer._dom.document.head); +} + +export default { + name: 'head-fastboot', + initialize: initialize +}; diff --git a/app/.gitkeep b/app/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/app/instance-initializers/browser/head.js b/app/instance-initializers/browser/head.js index 1080249..c40d8cc 100644 --- a/app/instance-initializers/browser/head.js +++ b/app/instance-initializers/browser/head.js @@ -1,7 +1,7 @@ import Ember from 'ember'; import ENV from '../../config/environment'; -export function initialize(instance) { +export function initialize(owner) { if (ENV['ember-cli-head'] && ENV['ember-cli-head']['suppressBrowserRender']) { return true; } // clear fast booted head (if any) @@ -9,9 +9,8 @@ export function initialize(instance) { .nextUntil('meta[name="ember-cli-head-end"] ~') .addBack() .remove(); - const container = instance.lookup ? instance : instance.container; - // const renderer = container.lookup('renderer:-dom'); - const component = container.lookup('component:head-layout'); + + const component = owner.lookup('component:head-layout'); component.appendTo(document.head); } diff --git a/app/instance-initializers/fastboot/head.js b/app/instance-initializers/fastboot/head.js index 8ef6b54..e461eea 100644 --- a/app/instance-initializers/fastboot/head.js +++ b/app/instance-initializers/fastboot/head.js @@ -1,16 +1,8 @@ -export function initialize(instance) { - const renderer = instance.lookup('renderer:-dom'); - const componentFactory = - instance._lookupFactory('component:head-layout'); - // explicitly set renderer & domhelper since we're in fastboot - const component = componentFactory.create( - instance.ownerInjection(), - { - renderer, - _domHelper: renderer._dom - } - ); - component.appendTo(renderer._dom.document.head); +export function initialize(owner) { + const document = owner.lookup('service:-document'); + const component = owner.lookup('component:head-layout'); + + component.appendTo(document.head); } export default { diff --git a/index.js b/index.js index ba8b8f0..c92cc45 100644 --- a/index.js +++ b/index.js @@ -1,12 +1,26 @@ /* jshint node: true */ 'use strict'; +var path = require('path'); var filterInitializers = require('fastboot-filter-initializers'); +var VersionChecker = require('ember-cli-version-checker'); +var mergeTrees = require('broccoli-merge-trees'); module.exports = { name: 'ember-cli-head', - treeForApp: function(tree) { + treeForApp: function(defaultTree) { + var checker = new VersionChecker(this); + var emberVersion = checker.for('ember', 'bower'); + + var trees = [defaultTree]; + + if (emberVersion.lt('2.9.0-alpha.4')) { + trees.push(this.treeGenerator(path.resolve(this.root, 'app-lt-2-9'))); + } + + var tree = mergeTrees(trees, { overwrite: true }); + return filterInitializers(tree); } }; diff --git a/package.json b/package.json index 0a56d74..0fcd714 100644 --- a/package.json +++ b/package.json @@ -43,9 +43,11 @@ "ember-addon" ], "dependencies": { + "broccoli-merge-trees": "^1.1.4", + "ember-cli-babel": "^5.1.5", "ember-cli-htmlbars": "^1.0.1", - "fastboot-filter-initializers": "0.0.1", - "ember-cli-babel": "^5.1.5" + "ember-cli-version-checker": "^1.1.6", + "fastboot-filter-initializers": "0.0.1" }, "ember-addon": { "configPath": "tests/dummy/config"