mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-28 01:56:01 -05:00
Micro optimizations to {{plugin-outlet}}
.
* Don't create a `ContainerView` if there is only one connection. * Don't create a virtual view if there are no connectors and the block form of the plugin isn't used.
This commit is contained in:
parent
8f2d1f7020
commit
61fb0f736b
1 changed files with 30 additions and 7 deletions
|
@ -2,6 +2,8 @@
|
|||
A plugin outlet is an extension point for templates where other templates can
|
||||
be inserted by plugins.
|
||||
|
||||
## Usage
|
||||
|
||||
If you handlebars template has:
|
||||
|
||||
```handlebars
|
||||
|
@ -27,6 +29,16 @@
|
|||
|
||||
And it will be wired up automatically.
|
||||
|
||||
## The block form
|
||||
|
||||
If you use the block form of the outlet, its contents will be displayed
|
||||
if no connectors are found. Example:
|
||||
|
||||
```handlebars
|
||||
{{#plugin-outlet "hello-world"}}
|
||||
Nobody says hello :'(
|
||||
{{/plugin-outlet}}
|
||||
```
|
||||
**/
|
||||
|
||||
var _connectorCache;
|
||||
|
@ -77,13 +89,24 @@ export default function(connectionName, options) {
|
|||
|
||||
var self = this;
|
||||
if (_connectorCache[connectionName]) {
|
||||
var CustomContainerView = Ember.ContainerView.extend({
|
||||
childViews: _connectorCache[connectionName].map(function(vc) {
|
||||
return vc.create({context: self});
|
||||
})
|
||||
});
|
||||
return Ember.Handlebars.helpers.view.call(this, CustomContainerView, options);
|
||||
} else {
|
||||
var view,
|
||||
childViews = _connectorCache[connectionName].map(function(vc) {
|
||||
return vc.create({ context: self });
|
||||
});
|
||||
|
||||
// If there is more than one view, create a container. Otherwise
|
||||
// just shove it in.
|
||||
if (childViews.length > 1) {
|
||||
view = Ember.ContainerView.extend({
|
||||
childViews: childViews
|
||||
});
|
||||
} else {
|
||||
view = childViews[0];
|
||||
}
|
||||
return Ember.Handlebars.helpers.view.call(this, view, options);
|
||||
} else if (options.fn) {
|
||||
|
||||
// If a block is passed, render its content.
|
||||
return Ember.Handlebars.helpers.view.call(this,
|
||||
Ember.View.extend({
|
||||
isVirtual: true,
|
||||
|
|
Loading…
Reference in a new issue