FIX: Raw plugin outlets were not working properly

This commit is contained in:
Robin Ward 2016-11-25 16:13:56 -05:00
parent 655b8a0540
commit 47a235e06a
1 changed files with 11 additions and 25 deletions

View File

@ -29,7 +29,7 @@
The list of disabled plugins is returned via the `Site` singleton.
**/
let _connectorCache, _rawCache, _templateCache;
let _connectorCache, _templateCache;
function findOutlets(collection, callback) {
const disabledPlugins = Discourse.Site.currentProp('disabled_plugins') || [];
@ -55,29 +55,20 @@ function findOutlets(collection, callback) {
export function clearCache() {
_templateCache = null;
_connectorCache = null;
_rawCache = null;
}
function buildConnectorCache() {
_connectorCache = {};
_rawCache = {};
_templateCache = [];
findOutlets(Ember.TEMPLATES, function(outletName, resource, uniqueName) {
if (/\.raw$/.test(uniqueName)) {
if (!_rawCache[outletName]) {
_rawCache[outletName] = [];
}
_rawCache[outletName].push(Ember.TEMPLATES[resource]);
} else {
_connectorCache[outletName] = _connectorCache[outletName] || [];
_connectorCache[outletName] = _connectorCache[outletName] || [];
_connectorCache[outletName].push({
templateName: resource.replace('javascripts/', ''),
template: Ember.TEMPLATES[resource],
classNames: `${outletName}-outlet ${uniqueName}`
});
}
_connectorCache[outletName].push({
templateName: resource.replace('javascripts/', ''),
template: Ember.TEMPLATES[resource],
classNames: `${outletName}-outlet ${uniqueName}`
});
});
Object.keys(_connectorCache).forEach(outletName => {
@ -91,16 +82,11 @@ function buildConnectorCache() {
// unbound version of outlets, only has a template
Handlebars.registerHelper('plugin-outlet', function(name) {
if (!_rawCache) { buildConnectorCache(); }
const functions = _rawCache[name];
if (functions) {
var output = [];
for(var i=0; i<functions.length; i++){
output.push(functions[i]({context: this}));
}
if (!_connectorCache) { buildConnectorCache(); }
const connector = _connectorCache[name];
if (connector && connector.length) {
const output = connector.map(c => c.template({context: this}));
return new Handlebars.SafeString(output.join(""));
}
});