FIX: Raw plugin outlets were broken

This commit is contained in:
Robin Ward 2017-01-05 11:38:43 -05:00
parent 80cd21e0a6
commit 7c8095294d
3 changed files with 43 additions and 3 deletions

View File

@ -1,7 +1,7 @@
import { connectorsFor } from 'discourse/lib/plugin-connectors';
import { rawConnectorsFor } from 'discourse/lib/plugin-connectors';
Handlebars.registerHelper('raw-plugin-outlet', function(args) {
const connectors = connectorsFor(args.hash.name);
const connectors = rawConnectorsFor(args.hash.name);
if (connectors.length) {
const output = connectors.map(c => c.template({context: this}));
return new Handlebars.SafeString(output.join(""));

View File

@ -1,4 +1,5 @@
let _connectorCache;
let _rawConnectorCache;
let _extraConnectorClasses = {};
let _classPaths;
@ -42,6 +43,7 @@ function findOutlets(collection, callback) {
export function clearCache() {
_connectorCache = null;
_rawConnectorCache = null;
}
function findClass(outletName, uniqueName) {
@ -63,7 +65,7 @@ function findClass(outletName, uniqueName) {
function buildConnectorCache() {
_connectorCache = {};
findOutlets(Ember.TEMPLATES, function(outletName, resource, uniqueName) {
findOutlets(Ember.TEMPLATES, (outletName, resource, uniqueName) => {
_connectorCache[outletName] = _connectorCache[outletName] || [];
_connectorCache[outletName].push({
@ -75,7 +77,22 @@ function buildConnectorCache() {
});
}
function buildRawConnectorCache() {
_rawConnectorCache = {};
findOutlets(Discourse.RAW_TEMPLATES, (outletName, resource) => {
_rawConnectorCache[outletName] = _rawConnectorCache[outletName] || [];
_rawConnectorCache[outletName].push({
template: Discourse.RAW_TEMPLATES[resource]
});
});
}
export function connectorsFor(outletName) {
if (!_connectorCache) { buildConnectorCache(); }
return _connectorCache[outletName] || [];
}
export function rawConnectorsFor(outletName) {
if (!_rawConnectorCache) { buildRawConnectorCache(); }
return _rawConnectorCache[outletName] || [];
}

View File

@ -0,0 +1,23 @@
import { acceptance } from "helpers/qunit-helpers";
const CONNECTOR = 'javascripts/raw-test/connectors/topic-list-tags/lala';
acceptance("Raw Plugin Outlet", {
setup() {
Discourse.RAW_TEMPLATES[CONNECTOR] = Handlebars.compile(
`<span class='topic-lala'>{{context.topic.id}}</span>`
);
},
teardown() {
delete Discourse.RAW_TEMPLATES[CONNECTOR];
}
});
test("Renders the raw plugin outlet", assert => {
visit("/");
andThen(() => {
assert.ok(find('.topic-lala').length > 0, 'it renders the outlet');
assert.equal(find('.topic-lala:eq(0)').text(), '11557', 'it has the topic id');
});
});