diff --git a/app/assets/javascripts/discourse/initializers/map-routes.js.es6 b/app/assets/javascripts/discourse/initializers/map-routes.js.es6 new file mode 100644 index 00000000000..3f08fa2a958 --- /dev/null +++ b/app/assets/javascripts/discourse/initializers/map-routes.js.es6 @@ -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); + }; + } +}; diff --git a/app/assets/javascripts/discourse/router.js.es6 b/app/assets/javascripts/discourse/router.js.es6 new file mode 100644 index 00000000000..70ca3b85768 --- /dev/null +++ b/app/assets/javascripts/discourse/router.js.es6 @@ -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; diff --git a/app/assets/javascripts/discourse/routes/discourse.js.es6 b/app/assets/javascripts/discourse/routes/discourse.js.es6 index 1f5bdab25f5..62c7b652dc9 100644 --- a/app/assets/javascripts/discourse/routes/discourse.js.es6 +++ b/app/assets/javascripts/discourse/routes/discourse.js.es6 @@ -110,106 +110,6 @@ const DiscourseRoute = Ember.Route.extend({ isPoppedState: function(transition) { 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; diff --git a/app/assets/javascripts/ember_include.js.erb b/app/assets/javascripts/ember_include.js.erb index 15cc71aec5b..759b468a37e 100644 --- a/app/assets/javascripts/ember_include.js.erb +++ b/app/assets/javascripts/ember_include.js.erb @@ -1,8 +1,8 @@ <% if Rails.env.development? || Rails.env.test? require_asset ("ember-template-compiler.js") - require_asset ("development/ember.js") + require_asset ("ember.debug.js") else - require_asset ("production/ember.js") + require_asset ("ember.prod.js") end %> diff --git a/app/assets/javascripts/jquery_include.js.erb b/app/assets/javascripts/jquery_include.js.erb index 6f509136a6d..0423ecabc10 100644 --- a/app/assets/javascripts/jquery_include.js.erb +++ b/app/assets/javascripts/jquery_include.js.erb @@ -1,7 +1,7 @@ <% if Rails.env.development? || Rails.env.test? - require_asset ("development/jquery-2.1.1.js") + require_asset ("jquery.debug.js") else - require_asset ("production/jquery-2.1.1.min.js") + require_asset ("jquery.prod.js") end %> diff --git a/app/assets/javascripts/main_include.js b/app/assets/javascripts/main_include.js index 48fce6d514b..a7113b3c850 100644 --- a/app/assets/javascripts/main_include.js +++ b/app/assets/javascripts/main_include.js @@ -67,6 +67,7 @@ //= require ./discourse/lib/emoji/emoji //= require ./discourse/lib/sharing //= require discourse/lib/desktop-notifications +//= require ./discourse/router //= require_tree ./discourse/dialects //= require_tree ./discourse/controllers diff --git a/app/views/common/_discourse_javascript.html.erb b/app/views/common/_discourse_javascript.html.erb index 7beae7ecb8e..a0755630520 100644 --- a/app/views/common/_discourse_javascript.html.erb +++ b/app/views/common/_discourse_javascript.html.erb @@ -36,8 +36,6 @@ PreloadStore.get("customEmoji").forEach(function(emoji) { Discourse.Dialect.registerEmoji(emoji.name, emoji.url); }); - Discourse.Router = Ember.Router.extend({ location: 'discourse-location' }); - Discourse.Route.mapRoutes(); Discourse.start(); Discourse.set('assetVersion','<%= Discourse.assets_digest %>'); Discourse.Session.currentProp("disableCustomCSS", <%= loading_admin? %>); diff --git a/test/javascripts/helpers/qunit-helpers.js.es6 b/test/javascripts/helpers/qunit-helpers.js.es6 index 054a4686a4d..06152caacc6 100644 --- a/test/javascripts/helpers/qunit-helpers.js.es6 +++ b/test/javascripts/helpers/qunit-helpers.js.es6 @@ -37,8 +37,6 @@ var oldAvatar = Discourse.Utilities.avatarImg; function acceptance(name, options) { module("Acceptance: " + name, { setup: function() { - Ember.run(Discourse, Discourse.advanceReadiness); - // Don't render avatars in acceptance tests, it's faster and no 404s Discourse.Utilities.avatarImg = () => ""; diff --git a/test/javascripts/test_helper.js b/test/javascripts/test_helper.js index 9935676b679..b99cb4b31d8 100644 --- a/test/javascripts/test_helper.js +++ b/test/javascripts/test_helper.js @@ -9,10 +9,10 @@ //= require ../../app/assets/javascripts/discourse/lib/probes // Externals we need to load first -//= require development/jquery-2.1.1 +//= require jquery.debug //= require jquery.ui.widget //= require handlebars -//= require development/ember +//= require ember.debug //= require message-bus //= require ember-qunit //= require fake_xml_http_request @@ -76,9 +76,7 @@ d.write('