Skip to content

Commit

Permalink
[WIP] Use latest visit API
Browse files Browse the repository at this point in the history
  • Loading branch information
chancancode committed Oct 9, 2015
1 parent c08e554 commit fbbd195
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 87 deletions.
65 changes: 0 additions & 65 deletions app/initializers/fastboot.js

This file was deleted.

14 changes: 3 additions & 11 deletions app/initializers/ajax.js → app/initializers/server/ajax.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*globals najax, FastBoot, Ember*/
/*globals najax, Ember*/
var nodeAjax = function(url, type, options) {
var adapter = this;

Expand All @@ -22,15 +22,7 @@ export default {
name: 'ajax-service',

initialize: function(application) {
// Detect if we're running in Node. If not, there's nothing to do.
if (typeof document === 'undefined') {
application.register('ajax:node', {
create: function() {
return nodeAjax;
}
});

application.inject('adapter', 'ajax', 'ajax:node');
}
application.register('ajax:node', nodeAjax, { instantiate: false });
application.inject('adapter', 'ajax', 'ajax:node');
}
};
17 changes: 17 additions & 0 deletions app/initializers/server/dom-helper-patches.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*globals Ember, URL*/
export default {
name: "dom-helper-patches",

initialize: function(App) {
// TODO: remove me
Ember.HTMLBars.DOMHelper.prototype.protocolForURL = function(url) {
var protocol = URL.parse(url).protocol;
return (protocol == null) ? ':' : protocol;
};

// TODO: remove me https://github.com/tildeio/htmlbars/pull/425
Ember.HTMLBars.DOMHelper.prototype.parseHTML = function(html) {
return this.document.createRawHTMLSection(html);
};
}
};
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/*globals Ember*/

// When using `ember fastboot --serve-assets` the application output will
// already be rendered to the DOM when the actual JavaScript loads. Ember
// does not automatically clear its `rootElement` so this leads to the
Expand All @@ -12,8 +14,7 @@ export default {
var originalDidCreateRootView = instance.didCreateRootView;

instance.didCreateRootView = function() {
Ember.$(instance.rootElement + ' .ember-view').remove();

Ember.$('.ember-view', instance.rootElement).remove();
originalDidCreateRootView.apply(instance, arguments);
};
}
Expand Down
67 changes: 60 additions & 7 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,32 @@
/* jshint node: true */
'use strict';

var Funnel = require('broccoli-funnel');

// Expose the an factory for the creating the `Application` object
// with the proper config at a known path, so that the server does
// not have to disover the app's module prefix ("my-app").
//
// The module defined here is prefixed with a `~` to make it less
// likely to collide with user code, since it is not possible to
// define a module with a name like this in the file system.
function fastbootAppModule(prefix) {
return [
"",
"define('~fastboot/app-factory', ['{{MODULE_PREFIX}}/app', '{{MODULE_PREFIX}}/config/environment'], function(App, config) {",
" App = App['default'];",
" config = config['default'];",
"",
" return {",
" 'default': function() {",
" return App.create(config);",
" }",
" };",
"});",
""
].join("\n").replace(/\{\{MODULE_PREFIX\}\}/g, prefix);
}

module.exports = {
name: 'ember-cli-fastboot',

Expand All @@ -11,6 +37,22 @@ module.exports = {
};
},

config: function(/* environment, appConfig */) {
// do nothing unless running `ember fastboot` command
if (!process.env.EMBER_CLI_FASTBOOT) { return {}; }

return {
autoRun: false,
storeConfigInMeta: false,
EmberENV: {
FEATURES: { 'ember-application-visit': true }
},
APP: {
autoBoot: false
}
};
},

contentFor: function(type, config) {
// do nothing unless running `ember fastboot` command
if (!process.env.EMBER_CLI_FASTBOOT) { return; }
Expand All @@ -23,17 +65,28 @@ module.exports = {
return "<!-- EMBER_CLI_FASTBOOT_TITLE -->";
}

if (type === 'vendor-prefix') {
return '// Added from ember-cli-fastboot \n' +
'EmberENV.FEATURES = EmberENV.FEATURES || {};\n' +
'EmberENV.FEATURES["ember-application-visit"] = true;\n';
if (type === 'app-boot') {
return fastbootAppModule(config.modulePrefix);
}
},

included: function() {
treeForApp: function(tree) {
if (process.env.EMBER_CLI_FASTBOOT) {
this.app.options.storeConfigInMeta = false;
process.env.EMBER_CLI_FASTBOOT_APP_NAME = this.app.name;
return new Funnel(tree, {
annotation: 'Funnel: Remove browser-only initializers',
exclude: [
'initializers/browser/*',
'instance-initializers/browser/*'
]
});
} else {
return new Funnel(tree, {
annotation: 'Funnel: Remove server-only initializers',
exclude: [
'initializers/server/*',
'instance-initializers/server/*'
]
});
}
}
};
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,14 @@
"configPath": "tests/dummy/config"
},
"dependencies": {
"broccoli-funnel": "0.2.8",
"chalk": "^0.5.1",
"contextify": "^0.1.11",
"debug": "^2.1.0",
"ember-fastboot-server": "0.0.2",
"express": "^4.8.5",
"glob": "^4.0.5",
"najax": "^0.1.5",
"rsvp": "^3.0.16",
"simple-dom": "^0.2.7"
"rsvp": "^3.0.16"
}
}

0 comments on commit fbbd195

Please sign in to comment.