Ember 1.11 broken WIP
This commit is contained in:
parent
b3b4fd21ed
commit
8294205f7c
|
@ -0,0 +1,15 @@
|
||||||
|
import { mapRoutes } from 'discourse/router';
|
||||||
|
|
||||||
|
export default {
|
||||||
|
name: "map-routes",
|
||||||
|
initialize(container, app) {
|
||||||
|
app.register('router:main', mapRoutes());
|
||||||
|
|
||||||
|
// HACK to fix: https://github.com/emberjs/ember.js/issues/10310
|
||||||
|
const originalBuildInstance = originalBuildInstance || Ember.Application.prototype.buildInstance;
|
||||||
|
Ember.Application.prototype.buildInstance = function() {
|
||||||
|
this.registry = this.buildRegistry();
|
||||||
|
return originalBuildInstance.apply(this);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
};
|
|
@ -0,0 +1,83 @@
|
||||||
|
const rootURL = Discourse.BaseUri && Discourse.BaseUri !== "/" ? Discourse.BaseUri : undefined;
|
||||||
|
|
||||||
|
const Router = Ember.Router.extend({
|
||||||
|
rootURL,
|
||||||
|
location: Ember.Test ? 'none': 'discourse-location'
|
||||||
|
});
|
||||||
|
|
||||||
|
export function mapRoutes() {
|
||||||
|
const resources = {};
|
||||||
|
const paths = {};
|
||||||
|
|
||||||
|
// If a module is defined as `route-map` in discourse or a plugin, its routes
|
||||||
|
// will be built automatically. You can supply a `resource` property to
|
||||||
|
// automatically put it in that resource, such as `admin`. That way plugins
|
||||||
|
// can define admin routes.
|
||||||
|
Ember.keys(requirejs._eak_seen).forEach(function(key) {
|
||||||
|
if (/route-map$/.test(key)) {
|
||||||
|
var module = require(key, null, null, true);
|
||||||
|
if (!module || !module.default) { throw new Error(key + ' must export a route map.'); }
|
||||||
|
|
||||||
|
var mapObj = module.default;
|
||||||
|
if (typeof mapObj === 'function') {
|
||||||
|
mapObj = { resource: 'root', map: mapObj };
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!resources[mapObj.resource]) { resources[mapObj.resource] = []; }
|
||||||
|
resources[mapObj.resource].push(mapObj.map);
|
||||||
|
if (mapObj.path) { paths[mapObj.resource] = mapObj.path; }
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
Router.map(function() {
|
||||||
|
var router = this;
|
||||||
|
|
||||||
|
// Do the root resources first
|
||||||
|
if (resources.root) {
|
||||||
|
resources.root.forEach(function(m) {
|
||||||
|
m.call(router);
|
||||||
|
});
|
||||||
|
delete resources.root;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Even if no plugins set it up, we need an `adminPlugins` route
|
||||||
|
var adminPlugins = 'admin.adminPlugins';
|
||||||
|
resources[adminPlugins] = resources[adminPlugins] || [Ember.K];
|
||||||
|
paths[adminPlugins] = paths[adminPlugins] || "/plugins";
|
||||||
|
|
||||||
|
var segments = {},
|
||||||
|
standalone = [];
|
||||||
|
|
||||||
|
Object.keys(resources).forEach(function(r) {
|
||||||
|
var m = /^([^\.]+)\.(.*)$/.exec(r);
|
||||||
|
if (m) {
|
||||||
|
segments[m[1]] = m[2];
|
||||||
|
} else {
|
||||||
|
standalone.push(r);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Apply other resources next. A little hacky but works!
|
||||||
|
standalone.forEach(function(r) {
|
||||||
|
router.resource(r, {path: paths[r]}, function() {
|
||||||
|
var res = this;
|
||||||
|
resources[r].forEach(function(m) { m.call(res); });
|
||||||
|
|
||||||
|
var s = segments[r];
|
||||||
|
if (s) {
|
||||||
|
var full = r + '.' + s;
|
||||||
|
res.resource(s, {path: paths[full]}, function() {
|
||||||
|
var nestedRes = this;
|
||||||
|
resources[full].forEach(function(m) { m.call(nestedRes); });
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
this.route('unknown', {path: '*path'});
|
||||||
|
});
|
||||||
|
|
||||||
|
return Router;
|
||||||
|
}
|
||||||
|
|
||||||
|
export default Router;
|
|
@ -110,106 +110,6 @@ const DiscourseRoute = Ember.Route.extend({
|
||||||
isPoppedState: function(transition) {
|
isPoppedState: function(transition) {
|
||||||
return (!transition._discourse_intercepted) && (!!transition.intent.url);
|
return (!transition._discourse_intercepted) && (!!transition.intent.url);
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
var routeBuilder;
|
|
||||||
|
|
||||||
DiscourseRoute.reopenClass({
|
|
||||||
|
|
||||||
buildRoutes: function(builder) {
|
|
||||||
var oldBuilder = routeBuilder;
|
|
||||||
routeBuilder = function() {
|
|
||||||
if (oldBuilder) oldBuilder.call(this);
|
|
||||||
return builder.call(this);
|
|
||||||
};
|
|
||||||
},
|
|
||||||
|
|
||||||
mapRoutes: function() {
|
|
||||||
var resources = {},
|
|
||||||
paths = {};
|
|
||||||
|
|
||||||
// If a module is defined as `route-map` in discourse or a plugin, its routes
|
|
||||||
// will be built automatically. You can supply a `resource` property to
|
|
||||||
// automatically put it in that resource, such as `admin`. That way plugins
|
|
||||||
// can define admin routes.
|
|
||||||
Ember.keys(requirejs._eak_seen).forEach(function(key) {
|
|
||||||
if (/route-map$/.test(key)) {
|
|
||||||
var module = require(key, null, null, true);
|
|
||||||
if (!module || !module.default) { throw new Error(key + ' must export a route map.'); }
|
|
||||||
|
|
||||||
var mapObj = module.default;
|
|
||||||
if (typeof mapObj === 'function') {
|
|
||||||
mapObj = { resource: 'root', map: mapObj };
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!resources[mapObj.resource]) { resources[mapObj.resource] = []; }
|
|
||||||
resources[mapObj.resource].push(mapObj.map);
|
|
||||||
if (mapObj.path) { paths[mapObj.resource] = mapObj.path; }
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
if (Discourse.BaseUri && Discourse.BaseUri !== "/") {
|
|
||||||
Discourse.Router.reopen({
|
|
||||||
rootURL: Discourse.BaseUri + "/"
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
Discourse.Router.map(function() {
|
|
||||||
var router = this;
|
|
||||||
|
|
||||||
// Do the root resources first
|
|
||||||
if (resources.root) {
|
|
||||||
resources.root.forEach(function(m) {
|
|
||||||
m.call(router);
|
|
||||||
});
|
|
||||||
delete resources.root;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Even if no plugins set it up, we need an `adminPlugins` route
|
|
||||||
var adminPlugins = 'admin.adminPlugins';
|
|
||||||
resources[adminPlugins] = resources[adminPlugins] || [Ember.K];
|
|
||||||
paths[adminPlugins] = paths[adminPlugins] || "/plugins";
|
|
||||||
|
|
||||||
var segments = {},
|
|
||||||
standalone = [];
|
|
||||||
|
|
||||||
Object.keys(resources).forEach(function(r) {
|
|
||||||
var m = /^([^\.]+)\.(.*)$/.exec(r);
|
|
||||||
if (m) {
|
|
||||||
segments[m[1]] = m[2];
|
|
||||||
} else {
|
|
||||||
standalone.push(r);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// Apply other resources next. A little hacky but works!
|
|
||||||
standalone.forEach(function(r) {
|
|
||||||
router.resource(r, {path: paths[r]}, function() {
|
|
||||||
var res = this;
|
|
||||||
resources[r].forEach(function(m) { m.call(res); });
|
|
||||||
|
|
||||||
var s = segments[r];
|
|
||||||
if (s) {
|
|
||||||
var full = r + '.' + s;
|
|
||||||
res.resource(s, {path: paths[full]}, function() {
|
|
||||||
var nestedRes = this;
|
|
||||||
resources[full].forEach(function(m) { m.call(nestedRes); });
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
if (routeBuilder) {
|
|
||||||
Ember.warn("The Discourse `routeBuilder` is deprecated. Export a `route-map` instead");
|
|
||||||
routeBuilder.call(router);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
this.route('unknown', {path: '*path'});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
export default DiscourseRoute;
|
export default DiscourseRoute;
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
<%
|
<%
|
||||||
if Rails.env.development? || Rails.env.test?
|
if Rails.env.development? || Rails.env.test?
|
||||||
require_asset ("ember-template-compiler.js")
|
require_asset ("ember-template-compiler.js")
|
||||||
require_asset ("development/ember.js")
|
require_asset ("ember.debug.js")
|
||||||
else
|
else
|
||||||
require_asset ("production/ember.js")
|
require_asset ("ember.prod.js")
|
||||||
end
|
end
|
||||||
%>
|
%>
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
<%
|
<%
|
||||||
if Rails.env.development? || Rails.env.test?
|
if Rails.env.development? || Rails.env.test?
|
||||||
require_asset ("development/jquery-2.1.1.js")
|
require_asset ("jquery.debug.js")
|
||||||
else
|
else
|
||||||
require_asset ("production/jquery-2.1.1.min.js")
|
require_asset ("jquery.prod.js")
|
||||||
end
|
end
|
||||||
%>
|
%>
|
||||||
|
|
|
@ -67,6 +67,7 @@
|
||||||
//= require ./discourse/lib/emoji/emoji
|
//= require ./discourse/lib/emoji/emoji
|
||||||
//= require ./discourse/lib/sharing
|
//= require ./discourse/lib/sharing
|
||||||
//= require discourse/lib/desktop-notifications
|
//= require discourse/lib/desktop-notifications
|
||||||
|
//= require ./discourse/router
|
||||||
|
|
||||||
//= require_tree ./discourse/dialects
|
//= require_tree ./discourse/dialects
|
||||||
//= require_tree ./discourse/controllers
|
//= require_tree ./discourse/controllers
|
||||||
|
|
|
@ -36,8 +36,6 @@
|
||||||
PreloadStore.get("customEmoji").forEach(function(emoji) {
|
PreloadStore.get("customEmoji").forEach(function(emoji) {
|
||||||
Discourse.Dialect.registerEmoji(emoji.name, emoji.url);
|
Discourse.Dialect.registerEmoji(emoji.name, emoji.url);
|
||||||
});
|
});
|
||||||
Discourse.Router = Ember.Router.extend({ location: 'discourse-location' });
|
|
||||||
Discourse.Route.mapRoutes();
|
|
||||||
Discourse.start();
|
Discourse.start();
|
||||||
Discourse.set('assetVersion','<%= Discourse.assets_digest %>');
|
Discourse.set('assetVersion','<%= Discourse.assets_digest %>');
|
||||||
Discourse.Session.currentProp("disableCustomCSS", <%= loading_admin? %>);
|
Discourse.Session.currentProp("disableCustomCSS", <%= loading_admin? %>);
|
||||||
|
|
|
@ -37,8 +37,6 @@ var oldAvatar = Discourse.Utilities.avatarImg;
|
||||||
function acceptance(name, options) {
|
function acceptance(name, options) {
|
||||||
module("Acceptance: " + name, {
|
module("Acceptance: " + name, {
|
||||||
setup: function() {
|
setup: function() {
|
||||||
Ember.run(Discourse, Discourse.advanceReadiness);
|
|
||||||
|
|
||||||
// Don't render avatars in acceptance tests, it's faster and no 404s
|
// Don't render avatars in acceptance tests, it's faster and no 404s
|
||||||
Discourse.Utilities.avatarImg = () => "";
|
Discourse.Utilities.avatarImg = () => "";
|
||||||
|
|
||||||
|
|
|
@ -9,10 +9,10 @@
|
||||||
//= require ../../app/assets/javascripts/discourse/lib/probes
|
//= require ../../app/assets/javascripts/discourse/lib/probes
|
||||||
|
|
||||||
// Externals we need to load first
|
// Externals we need to load first
|
||||||
//= require development/jquery-2.1.1
|
//= require jquery.debug
|
||||||
//= require jquery.ui.widget
|
//= require jquery.ui.widget
|
||||||
//= require handlebars
|
//= require handlebars
|
||||||
//= require development/ember
|
//= require ember.debug
|
||||||
//= require message-bus
|
//= require message-bus
|
||||||
//= require ember-qunit
|
//= require ember-qunit
|
||||||
//= require fake_xml_http_request
|
//= require fake_xml_http_request
|
||||||
|
@ -76,9 +76,7 @@ d.write('<style>#ember-testing-container { position: absolute; background: white
|
||||||
Discourse.rootElement = '#ember-testing';
|
Discourse.rootElement = '#ember-testing';
|
||||||
Discourse.setupForTesting();
|
Discourse.setupForTesting();
|
||||||
Discourse.injectTestHelpers();
|
Discourse.injectTestHelpers();
|
||||||
Discourse.runInitializers();
|
|
||||||
Discourse.start();
|
Discourse.start();
|
||||||
Discourse.Route.mapRoutes();
|
|
||||||
|
|
||||||
// disable logster error reporting
|
// disable logster error reporting
|
||||||
if (window.Logster) {
|
if (window.Logster) {
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because one or more lines are too long
File diff suppressed because it is too large
Load Diff
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue