Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clear fast boot rendered head on browser boot #2

Merged
merged 3 commits into from
Mar 1, 2016
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 0 additions & 25 deletions addon/instance-initializers/head.js

This file was deleted.

1 change: 1 addition & 0 deletions addon/templates/components/head-layout.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<meta name="ember-cli-head-start" />{{head-content}}<meta name="ember-cli-head-end" />
7 changes: 7 additions & 0 deletions app/components/head-layout.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import Ember from 'ember';
import layout from 'ember-cli-head/templates/components/head-layout';

export default Ember.Component.extend({
tagName: '',
layout
});
18 changes: 18 additions & 0 deletions app/instance-initializers/browser/head.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import Ember from 'ember';

export function initialize(instance) {
// 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;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be able to remove this conditional, fastboot only supports ember 2.3.0+ so instance.lookup should always be present.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. 👍

const renderer = container.lookup('renderer:-dom');
const component = container.lookup('component:head-layout');
component.appendTo(renderer._dom.document.head);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In browser mode, can we just always specify document.head?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll give that a try.

}

export default {
name: 'head-browser',
initialize: initialize
};
20 changes: 20 additions & 0 deletions app/instance-initializers/fastboot/head.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
export function initialize(instance) {
const container = instance.lookup ? instance : instance.container;
const renderer = container.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
};
1 change: 0 additions & 1 deletion app/instance-initializers/head.js

This file was deleted.

15 changes: 15 additions & 0 deletions tests/integration/components/head-layout-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { moduleForComponent, test } from 'ember-qunit';
import hbs from 'htmlbars-inline-precompile';

moduleForComponent('head-layout', 'Integration | Component | head layout', {
integration: true
});

test('it renders', function(assert) {

this.render(hbs`{{head-layout}}`);

assert.equal(this.$('meta[name="ember-cli-head-start"]').length, 1);
assert.equal(this.$('meta[name="ember-cli-head-end"]').length, 1);

});