Skip to content

Commit

Permalink
Merge pull request #22 from rwjblue/title
Browse files Browse the repository at this point in the history
Add title handling.
  • Loading branch information
rwjblue committed Apr 23, 2015
2 parents bfce2ca + b1173b5 commit 1607ceb
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 7 deletions.
8 changes: 6 additions & 2 deletions app/initializers/fastboot.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export default {

return App.visit(url).then(function(instance) {
var view = instance.view;

var title = view.renderer._dom.document.title;
var element;

Ember.run(function() {
Expand All @@ -44,7 +44,11 @@ export default {
element = element.firstChild;

var serializer = new SimpleDOM.HTMLSerializer(SimpleDOM.voidMap);
return serializer.serialize(element);

return {
body: serializer.serialize(element),
title: title
};
});
});
}
Expand Down
4 changes: 4 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ module.exports = {
return "<!-- EMBER_CLI_FASTBOOT_BODY -->";
}

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

if (type === 'vendor-prefix') {
return '// Added from ember-cli-fastboot \n' +
'EmberENV.FEATURES = EmberENV.FEATURES || {};\n' +
Expand Down
14 changes: 9 additions & 5 deletions lib/models/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,19 @@ FastBootServer.prototype.log = function(statusCode, message) {
this.ui.writeLine(chalk[color](statusCode) + " " + message);
};

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

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

return html;
};

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

FastBootServer.prototype.handleFailure = function(res, path, error) {
Expand Down Expand Up @@ -65,8 +69,8 @@ FastBootServer.prototype.middleware = function() {
debug("finished handling; url=%s", path);
});

function success(body) {
server.handleSuccess(res, path, body);
function success(result) {
server.handleSuccess(res, path, result);
}

function failure(error) {
Expand Down
2 changes: 2 additions & 0 deletions tests/acceptance/simple-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,11 @@ describe('simple acceptance', function() {
return request('http://localhost:49741/')
.then(function(response) {
expect(response.body).to.contain("Welcome to Ember.js");
expect(response.body).to.contain('Application Route -- Title');
});
});


it('/posts HTML contents', function() {
return request('http://localhost:49741/posts')
.then(function(response) {
Expand Down
10 changes: 10 additions & 0 deletions tests/dummy/app/routes/application.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import Ember from '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');
}
}
});

0 comments on commit 1607ceb

Please sign in to comment.