From 5881f6855665da309c2d28701dfa416488adcc50 Mon Sep 17 00:00:00 2001 From: Robin Ward Date: Fri, 4 Sep 2015 16:08:45 -0400 Subject: [PATCH] Support for rewiring plugin outlets so we can move Akismet up --- .../discourse/helpers/plugin-outlet.js.es6 | 26 +++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/app/assets/javascripts/discourse/helpers/plugin-outlet.js.es6 b/app/assets/javascripts/discourse/helpers/plugin-outlet.js.es6 index 6e8bbcc0d98..d9e76878b0c 100644 --- a/app/assets/javascripts/discourse/helpers/plugin-outlet.js.es6 +++ b/app/assets/javascripts/discourse/helpers/plugin-outlet.js.es6 @@ -47,6 +47,13 @@ **/ +// TODO: Add all plugin-outlet names dynamically +const rewireableOutlets = [ + 'hamburger-admin' +]; + +const _rewires = {}; + let _connectorCache, _rawCache; function findOutlets(collection, callback) { @@ -63,9 +70,17 @@ function findOutlets(collection, callback) { } const segments = res.split("/"); - const outletName = segments[segments.length-2]; + let outletName = segments[segments.length-2]; const uniqueName = segments[segments.length-1]; + const outletRewires = _rewires[outletName]; + if (outletRewires) { + const newOutlet = outletRewires[uniqueName]; + if (newOutlet) { + outletName = newOutlet; + } + } + const dashedName = outletName.replace(/_/g, '-'); if (dashedName !== outletName) { Ember.warn("DEPRECATION: You need to use dashes in outlet names, not underscores"); @@ -179,4 +194,11 @@ Ember.HTMLBars._registerHelper('plugin-outlet', function(params, hash, options, } }); - +// Allow plugins to rewire outlets to new outlets if they exist. For example, the akismet +// plugin will use `hamburger-admin` if it exists, otherwise `site-menu-links` +export function rewire(uniqueName, outlet, wantedOutlet) { + if (rewireableOutlets.indexOf(wantedOutlet) !== -1) { + _rewires[outlet] = _rewires[outlet] || {}; + _rewires[outlet][uniqueName] = wantedOutlet; + } +}