Skip to content

Commit

Permalink
Merge pull request #15 from ronco/feature/head-component-support
Browse files Browse the repository at this point in the history
Serialize head component if present
  • Loading branch information
tomdale committed Feb 10, 2016
2 parents 8ee9faf + 9087bb5 commit 57a5ebc
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
5 changes: 5 additions & 0 deletions lib/ember-app.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,15 @@ EmberApp.prototype.visit = function(url) {
var options = { isBrowser: false, document: doc, rootElement: rootElement };

return this._app.visit(url, options).then(function(instance) {
var head;
if (doc.head) {
head = HTMLSerializer.serialize(doc.head);
}
try {
return {
url: instance.getURL(), // TODO: use this to determine whether to 200 or redirect
title: doc.title,
head: head,
body: HTMLSerializer.serialize(rootElement) // This matches the current code; but we probably want `serializeChildren` here
};
} finally {
Expand Down
7 changes: 5 additions & 2 deletions lib/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,22 @@ FastBootServer.prototype.log = function(statusCode, message, startTime) {
this.ui.writeLine(chalk.blue(now.toISOString()) + " " + chalk[color](statusCode) + " " + message);
};

FastBootServer.prototype.insertIntoIndexHTML = function(title, body) {
FastBootServer.prototype.insertIntoIndexHTML = function(title, body, head) {
var html = this.html.replace("<!-- EMBER_CLI_FASTBOOT_BODY -->", body);

if (title) {
html = html.replace("<!-- EMBER_CLI_FASTBOOT_TITLE -->", "<title>" + title + "</title>");
}
if (head) {
html = html.replace("<!-- EMBER_CLI_FASTBOOT_HEAD -->", head);
}

return html;
};

FastBootServer.prototype.handleSuccess = function(res, path, result, startTime) {
this.log(200, 'OK ' + path, startTime);
res.send(this.insertIntoIndexHTML(result.title, result.body));
res.send(this.insertIntoIndexHTML(result.title, result.body, result.head));
};

FastBootServer.prototype.handleFailure = function(res, path, error, startTime) {
Expand Down

0 comments on commit 57a5ebc

Please sign in to comment.