FEATURE: add support for plugin-outlet in raw templates
This commit is contained in:
parent
e26688c112
commit
cc9f6e53f2
|
@ -47,7 +47,7 @@
|
|||
|
||||
**/
|
||||
|
||||
let _connectorCache;
|
||||
let _connectorCache, _rawCache;
|
||||
|
||||
function findOutlets(collection, callback) {
|
||||
|
||||
|
@ -73,6 +73,7 @@ function findOutlets(collection, callback) {
|
|||
|
||||
function buildConnectorCache() {
|
||||
_connectorCache = {};
|
||||
_rawCache = {};
|
||||
|
||||
const uniqueViews = {};
|
||||
findOutlets(requirejs._eak_seen, function(outletName, resource, uniqueName) {
|
||||
|
@ -93,10 +94,23 @@ function buildConnectorCache() {
|
|||
// We are going to add it back with the proper template
|
||||
_connectorCache[outletName].removeObject(viewClass);
|
||||
} else {
|
||||
viewClass = Em.View.extend({ classNames: [outletName + '-outlet', uniqueName] });
|
||||
if (!/\.raw$/.test(uniqueName)) {
|
||||
viewClass = Em.View.extend({ classNames: [outletName + '-outlet', uniqueName] });
|
||||
}
|
||||
}
|
||||
|
||||
if (viewClass) {
|
||||
_connectorCache[outletName].pushObject(viewClass.extend(mixin));
|
||||
} else {
|
||||
// we have a raw template
|
||||
if (!_rawCache[outletName]) {
|
||||
_rawCache[outletName] = [];
|
||||
}
|
||||
|
||||
_rawCache[outletName].push(Ember.TEMPLATES[resource]);
|
||||
}
|
||||
_connectorCache[outletName].pushObject(viewClass.extend(mixin));
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
var _viewInjections;
|
||||
|
@ -113,6 +127,24 @@ function viewInjections(container) {
|
|||
return _viewInjections;
|
||||
}
|
||||
|
||||
// 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}));
|
||||
}
|
||||
|
||||
return new Handlebars.SafeString(output.join(""));
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
Ember.HTMLBars._registerHelper('plugin-outlet', function(params, hash, options, env) {
|
||||
const connectionName = params[0];
|
||||
|
||||
|
@ -139,3 +171,5 @@ Ember.HTMLBars._registerHelper('plugin-outlet', function(params, hash, options,
|
|||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
import registerUnbound from 'discourse/helpers/register-unbound';
|
||||
import { runFilters } from 'discourse/lib/filter';
|
||||
|
||||
registerUnbound('topic-link', function(topic) {
|
||||
var title = topic.get('fancyTitle');
|
||||
|
@ -8,7 +7,5 @@ registerUnbound('topic-link', function(topic) {
|
|||
var extraClass = topic.get('last_read_post_number') === topic.get('highest_post_number') ? " visited" : "";
|
||||
var string = "<a href='" + url + "' class='title" + extraClass + "'>" + title + "</a>";
|
||||
|
||||
string = runFilters('topic-link', string, topic);
|
||||
|
||||
return new Handlebars.SafeString(string);
|
||||
});
|
||||
|
|
|
@ -1,24 +0,0 @@
|
|||
var filters = {};
|
||||
|
||||
// use filter API to register a callback from a plugin
|
||||
const filter = function(name, fn) {
|
||||
var current = filters[name] = filters[name] || [];
|
||||
current.push(fn);
|
||||
};
|
||||
|
||||
const runFilters = function(name, val) {
|
||||
const current = filters[name];
|
||||
if (current) {
|
||||
|
||||
var args = Array.prototype.slice.call(arguments, 1);
|
||||
|
||||
for(var i = 0; i < current.length; i++) {
|
||||
val = current[i].apply(this, args);
|
||||
}
|
||||
}
|
||||
|
||||
return val;
|
||||
};
|
||||
|
||||
export { runFilters };
|
||||
export default filter;
|
|
@ -2,7 +2,7 @@
|
|||
<li>
|
||||
<a class='search-link' href='{{unbound result.url}}'>
|
||||
<span class='topic'>
|
||||
{{topic-status topic=result.topic disableActions=true}}<span class='topic-title'>{{unbound result.topic.title}}</span>{{category-badge result.topic.category}}
|
||||
{{topic-status topic=result.topic disableActions=true}}<span class='topic-title'>{{unbound result.topic.title}}</span>{{category-badge result.topic.category}}{{plugin-outlet "search-category"}}
|
||||
</span>
|
||||
{{#unless site.mobileView}}
|
||||
<span class='blurb'>
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
{{#if controller.showTopicPostBadges}}
|
||||
{{raw "topic-post-badges" unread=topic.unread newPosts=topic.displayNewPosts unseen=topic.unseen url=topic.lastUnreadUrl}}
|
||||
{{/if}}
|
||||
{{plugin-outlet "topic-list-tags"}}
|
||||
{{#if expandPinned}}
|
||||
{{raw "list/topic-excerpt" topic=topic}}
|
||||
{{/if}}
|
||||
|
|
Loading…
Reference in New Issue