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

Allow Populating Head Content #66

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
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
14 changes: 7 additions & 7 deletions app/initializers/fastboot.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,19 +44,19 @@ export default {
});

return promise.then(function(instance) {
var serializer = new SimpleDOM.HTMLSerializer(SimpleDOM.voidMap);
var view = instance.view;
var title = view.renderer._dom.document.title;
var element;
var dom = view.renderer._dom;
var head = dom.document.head;
var body;

Ember.run(function() {
element = view.renderToElement();
body = view.renderToElement();
});

var serializer = new SimpleDOM.HTMLSerializer(SimpleDOM.voidMap);

return {
body: serializer.serialize(element),
title: title
body: serializer.serializeChildren(body),
head: (head === null) ? null : serializer.serializeChildren(head)
};
});
});
Expand Down
8 changes: 4 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ module.exports = {
// do nothing unless running `ember fastboot` command
if (!process.env.EMBER_CLI_FASTBOOT) { return; }

if (type === 'body') {
return "<!-- EMBER_CLI_FASTBOOT_BODY -->";
if (type === 'head') {
return "<!-- EMBER_CLI_FASTBOOT_HEAD -->";
}

if (type === 'head') {
return "<!-- EMBER_CLI_FASTBOOT_TITLE -->";
if (type === 'body') {
return "<!-- EMBER_CLI_FASTBOOT_BODY -->";
}

if (type === 'vendor-prefix') {
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@
"chalk": "^0.5.1",
"contextify": "^0.1.11",
"debug": "^2.1.0",
"ember-fastboot-server": "0.0.2",
"ember-fastboot-server": "ronco/ember-fastboot-server#fastboot-head-content",
"express": "^4.8.5",
"glob": "^4.0.5",
"najax": "^0.1.5",
"rsvp": "^3.0.16",
"simple-dom": "^0.2.7"
"simple-dom": "ronco/simple-dom#serialize-children"
}
}
4 changes: 4 additions & 0 deletions tests/acceptance/simple-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ describe('simple acceptance', function() {
expect(response.statusCode).to.equal(200);
expect(response.headers["content-type"]).to.eq("text/html; charset=utf-8");
expect(response.body).to.contain('<title>Application Route -- Title</title>');
expect(response.body).to.contain('<meta name="description" content="something here">');
expect(response.body).to.contain('<meta property="og:image" content="http://placehold.it/500x500">');
expect(response.body).to.contain("Welcome to Ember.js");
});
});
Expand All @@ -39,6 +41,8 @@ describe('simple acceptance', function() {
expect(response.statusCode).to.equal(200);
expect(response.headers["content-type"]).to.eq("text/html; charset=utf-8");
expect(response.body).to.contain('<title>Application Route -- Title</title>');
expect(response.body).to.contain('<meta name="description" content="something here">');
expect(response.body).to.contain('<meta property="og:image" content="http://placehold.it/500x500">');
expect(response.body).to.contain("Welcome to Ember.js");
expect(response.body).to.contain("Posts Route!");
});
Expand Down
1 change: 0 additions & 1 deletion tests/dummy/app/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>Dummy</title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">

{{content-for 'head'}}
Expand Down
23 changes: 21 additions & 2 deletions tests/dummy/app/routes/application.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,29 @@
import Ember from 'ember';

const { get } = Ember;

export default Ember.Route.extend({
actions: {
didTransition: function() {
var renderer = this.container.lookup('renderer:-dom');
Ember.set(renderer, '_dom.document.title', 'Application Route -- Title');
let renderer = this.container.lookup('renderer:-dom');
if (renderer) {
let document = get(renderer, '_dom.document');
if (!document) { return; }
let element;
element = document.createElement('title');
element.appendChild(document.createTextNode('Application Route -- Title'));
document.head.appendChild(element);

element = document.createElement('meta');
element.setAttribute('name', 'description');
element.setAttribute('content', 'something here');
document.head.appendChild(element);

element = document.createElement('meta');
element.setAttribute('property', 'og:image');
element.setAttribute('content', 'http://placehold.it/500x500');
document.head.appendChild(element);
}
}
}
});