Skip to content

Commit 789b62e

Browse files
committed
Merge pull request #2 from ronco/kill-double-head
Clear fast boot rendered head on browser boot
2 parents 79337af + 0f6a1c2 commit 789b62e

9 files changed

Lines changed: 67 additions & 26 deletions

File tree

addon/instance-initializers/head.js

Lines changed: 0 additions & 25 deletions
This file was deleted.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<meta name="ember-cli-head-start" />{{head-content}}<meta name="ember-cli-head-end" />

app/components/head-layout.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import Ember from 'ember';
2+
import layout from 'ember-cli-head/templates/components/head-layout';
3+
4+
export default Ember.Component.extend({
5+
tagName: '',
6+
layout
7+
});
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import Ember from 'ember';
2+
3+
export function initialize(instance) {
4+
// clear fast booted head (if any)
5+
Ember.$('meta[name="ember-cli-head-start"]')
6+
.nextUntil('meta[name="ember-cli-head-end"] ~')
7+
.addBack()
8+
.remove();
9+
const container = instance.lookup ? instance : instance.container;
10+
// const renderer = container.lookup('renderer:-dom');
11+
const component = container.lookup('component:head-layout');
12+
component.appendTo(document.head);
13+
}
14+
15+
export default {
16+
name: 'head-browser',
17+
initialize: initialize
18+
};
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
export function initialize(instance) {
2+
const renderer = instance.lookup('renderer:-dom');
3+
const componentFactory =
4+
instance._lookupFactory('component:head-layout');
5+
// explicitly set renderer & domhelper since we're in fastboot
6+
const component = componentFactory.create(
7+
instance.ownerInjection(),
8+
{
9+
renderer,
10+
_domHelper: renderer._dom
11+
}
12+
);
13+
component.appendTo(renderer._dom.document.head);
14+
}
15+
16+
export default {
17+
name: 'head-fastboot',
18+
initialize: initialize
19+
};

app/instance-initializers/head.js

Lines changed: 0 additions & 1 deletion
This file was deleted.

index.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
11
/* jshint node: true */
22
'use strict';
33

4+
var filterInitializers = require('fastboot-filter-initializers');
5+
46
module.exports = {
57
name: 'ember-cli-head',
68
isDevelopingAddon: function() {
79
return true;
10+
},
11+
12+
treeForApp: function(tree) {
13+
return filterInitializers(tree);
814
}
915
};

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
],
4545
"dependencies": {
4646
"ember-cli-htmlbars": "^1.0.1",
47+
"fastboot-filter-initializers": "0.0.1",
4748
"ember-cli-babel": "^5.1.5"
4849
},
4950
"ember-addon": {
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { moduleForComponent, test } from 'ember-qunit';
2+
import hbs from 'htmlbars-inline-precompile';
3+
4+
moduleForComponent('head-layout', 'Integration | Component | head layout', {
5+
integration: true
6+
});
7+
8+
test('it renders', function(assert) {
9+
10+
this.render(hbs`{{head-layout}}`);
11+
12+
assert.equal(this.$('meta[name="ember-cli-head-start"]').length, 1);
13+
assert.equal(this.$('meta[name="ember-cli-head-end"]').length, 1);
14+
15+
});

0 commit comments

Comments
 (0)