From 2efe4900cf432b289f428b10346e6adf44c01250 Mon Sep 17 00:00:00 2001 From: Robin Ward Date: Fri, 9 Dec 2016 13:51:26 -0500 Subject: [PATCH] Plugin Outlets need their arguments to be explicit --- .../javascripts/admin/templates/admin.hbs | 2 +- .../javascripts/admin/templates/dashboard.hbs | 2 +- .../javascripts/admin/templates/group.hbs | 2 +- .../discourse-common/resolver.js.es6 | 9 ++ .../components/plugin-connector.js.es6 | 19 +++ .../discourse/components/plugin-outlet.js.es6 | 51 +++++++ .../discourse/helpers/plugin-outlet.js.es6 | 141 ------------------ .../helpers/raw-plugin-outlet.js.es6 | 9 ++ .../discourse/lib/plugin-connectors.js.es6 | 67 +++++++++ .../discourse/templates/application.hbs | 8 +- .../templates/components/bread-crumbs.hbs | 2 +- .../components/edit-category-settings.hbs | 4 +- .../templates/components/navigation-bar.hbs | 2 +- .../templates/components/plugin-outlet.hbs | 3 + .../templates/components/stream-item.hbs | 2 +- .../templates/components/topic-category.hbs | 2 +- .../components/topic-footer-buttons.hbs | 8 +- .../components/user-card-contents.hbs | 6 +- .../discourse/templates/composer.hbs | 6 +- .../discourse/templates/discovery.hbs | 4 +- .../discourse/templates/full-page-search.hbs | 2 +- .../templates/list/topic-list-item.raw.hbs | 4 +- .../mobile/list/topic-list-item.raw.hbs | 2 +- .../templates/modal/create-account.hbs | 6 +- .../discourse/templates/modal/history.hbs | 2 +- .../discourse/templates/preferences.hbs | 4 +- .../discourse/templates/static.hbs | 2 +- .../discourse/templates/tags/show.hbs | 2 +- .../javascripts/discourse/templates/topic.hbs | 10 +- .../javascripts/discourse/templates/user.hbs | 15 +- .../discourse/templates/user/activity.hbs | 4 +- .../discourse/templates/user/summary.hbs | 4 +- .../plugin-outlet-connector-class-test.js.es6 | 47 ++++++ .../plugin-outlet-multi-template-test.js.es6 | 2 +- .../plugin-outlet-single-template-test.js.es6 | 8 +- test/javascripts/helpers/qunit-helpers.js.es6 | 5 +- 36 files changed, 272 insertions(+), 196 deletions(-) create mode 100644 app/assets/javascripts/discourse/components/plugin-connector.js.es6 create mode 100644 app/assets/javascripts/discourse/components/plugin-outlet.js.es6 delete mode 100644 app/assets/javascripts/discourse/helpers/plugin-outlet.js.es6 create mode 100644 app/assets/javascripts/discourse/helpers/raw-plugin-outlet.js.es6 create mode 100644 app/assets/javascripts/discourse/lib/plugin-connectors.js.es6 create mode 100644 app/assets/javascripts/discourse/templates/components/plugin-outlet.hbs create mode 100644 test/javascripts/acceptance/plugin-outlet-connector-class-test.js.es6 diff --git a/app/assets/javascripts/admin/templates/admin.hbs b/app/assets/javascripts/admin/templates/admin.hbs index 77904edc48b..7f34c00b772 100644 --- a/app/assets/javascripts/admin/templates/admin.hbs +++ b/app/assets/javascripts/admin/templates/admin.hbs @@ -23,7 +23,7 @@ {{nav-item route='admin.backups' label='admin.backups.title'}} {{/if}} {{nav-item route='adminPlugins' label='admin.plugins.title'}} - {{plugin-outlet "admin-menu" tagName="li"}} + {{plugin-outlet name="admin-menu" connectorTagName="li"}}
diff --git a/app/assets/javascripts/admin/templates/dashboard.hbs b/app/assets/javascripts/admin/templates/dashboard.hbs index e02a5a925ca..ec7753ac6c9 100644 --- a/app/assets/javascripts/admin/templates/dashboard.hbs +++ b/app/assets/javascripts/admin/templates/dashboard.hbs @@ -1,4 +1,4 @@ -{{plugin-outlet "admin-dashboard-top"}} +{{plugin-outlet name="admin-dashboard-top"}} {{#conditional-loading-spinner condition=loading}}
diff --git a/app/assets/javascripts/admin/templates/group.hbs b/app/assets/javascripts/admin/templates/group.hbs index f66e0ca8557..26cee25498d 100644 --- a/app/assets/javascripts/admin/templates/group.hbs +++ b/app/assets/javascripts/admin/templates/group.hbs @@ -121,7 +121,7 @@ {{#if siteSettings.email_in}} {{text-field name="incoming_email" value=model.incoming_email placeholderKey="admin.groups.incoming_email_placeholder"}} - {{plugin-outlet "group-email-in"}} + {{plugin-outlet name="group-email-in" args=(hash model=model)}} {{/if}} {{/unless}} diff --git a/app/assets/javascripts/discourse-common/resolver.js.es6 b/app/assets/javascripts/discourse-common/resolver.js.es6 index 7e1bf585e09..6d5d2355b16 100644 --- a/app/assets/javascripts/discourse-common/resolver.js.es6 +++ b/app/assets/javascripts/discourse-common/resolver.js.es6 @@ -137,12 +137,21 @@ export function buildResolver(baseName) { return this._super(parsedName); }, + findConnectorTemplate(parsedName) { + const full = parsedName.fullNameWithoutType.replace('components/', ''); + if (full.indexOf('connectors') === 0) { + return Ember.TEMPLATES[`javascripts/${full}`]; + } + + }, + resolveTemplate(parsedName) { return this.findPluginMobileTemplate(parsedName) || this.findPluginTemplate(parsedName) || this.findMobileTemplate(parsedName) || this.findTemplate(parsedName) || this.findLoadingTemplate(parsedName) || + this.findConnectorTemplate(parsedName) || Ember.TEMPLATES.not_found; }, diff --git a/app/assets/javascripts/discourse/components/plugin-connector.js.es6 b/app/assets/javascripts/discourse/components/plugin-connector.js.es6 new file mode 100644 index 00000000000..2773e642f7a --- /dev/null +++ b/app/assets/javascripts/discourse/components/plugin-connector.js.es6 @@ -0,0 +1,19 @@ +export default Ember.Component.extend({ + + init() { + this._super(); + + const connector = this.get('connector'); + this.set('layoutName', connector.templateName); + + const args = this.get('args') || {}; + Object.keys(args).forEach(key => this.set(key, args[key])); + }, + + send(name, ...args) { + const connectorClass = this.get('connector.connectorClass'); + const action = connectorClass.actions[name]; + return action ? action.call(this, ...args) : this._super(name, ...args); + } + +}); diff --git a/app/assets/javascripts/discourse/components/plugin-outlet.js.es6 b/app/assets/javascripts/discourse/components/plugin-outlet.js.es6 new file mode 100644 index 00000000000..5fd2d2a77c6 --- /dev/null +++ b/app/assets/javascripts/discourse/components/plugin-outlet.js.es6 @@ -0,0 +1,51 @@ +/** + A plugin outlet is an extension point for templates where other templates can + be inserted by plugins. + + ## Usage + + If your handlebars template has: + + ```handlebars + {{plugin-outlet name="evil-trout"}} + ``` + + Then any handlebars files you create in the `connectors/evil-trout` directory + will automatically be appended. For example: + + plugins/hello/assets/javascripts/discourse/templates/connectors/evil-trout/hello.hbs + + With the contents: + + ```handlebars + Hello World + ``` + + Will insert Hello World at that point in the template. + + ## Disabling + + If a plugin returns a disabled status, the outlets will not be wired up for it. + The list of disabled plugins is returned via the `Site` singleton. + +**/ +import { connectorsFor } from 'discourse/lib/plugin-connectors'; + +export default Ember.Component.extend({ + tagName: 'span', + connectors: null, + + init() { + this._super(); + const name = this.get('name'); + + if (name) { + const args = this.get('args'); + const connectors = connectorsFor(name).filter(con => { + return con.connectorClass.shouldRender(args); + }); + + this.set('connectors', connectors); + } + } +}); diff --git a/app/assets/javascripts/discourse/helpers/plugin-outlet.js.es6 b/app/assets/javascripts/discourse/helpers/plugin-outlet.js.es6 deleted file mode 100644 index f8831bc8780..00000000000 --- a/app/assets/javascripts/discourse/helpers/plugin-outlet.js.es6 +++ /dev/null @@ -1,141 +0,0 @@ -/** - A plugin outlet is an extension point for templates where other templates can - be inserted by plugins. - - ## Usage - - If your handlebars template has: - - ```handlebars - {{plugin-outlet "evil-trout"}} - ``` - - Then any handlebars files you create in the `connectors/evil-trout` directory - will automatically be appended. For example: - - plugins/hello/assets/javascripts/discourse/templates/connectors/evil-trout/hello.hbs - - With the contents: - - ```handlebars - Hello World - ``` - - Will insert Hello World at that point in the template. - - ## Disabling - - If a plugin returns a disabled status, the outlets will not be wired up for it. - The list of disabled plugins is returned via the `Site` singleton. - -**/ -let _connectorCache, _templateCache; - -function findOutlets(collection, callback) { - const disabledPlugins = Discourse.Site.currentProp('disabled_plugins') || []; - - Object.keys(collection).forEach(function(res) { - if (res.indexOf("/connectors/") !== -1) { - // Skip any disabled plugins - for (let i=0; i { - const connector = _connectorCache[outletName]; - (connector || []).forEach(s => { - _templateCache.push(s.template); - s.templateId = parseInt(_templateCache.length - 1); - }); - }); -} - -// unbound version of outlets, only has a template -Handlebars.registerHelper('plugin-outlet', function(name) { - 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("")); - } -}); - -export default Ember.Helper.helper(function() { -}); - -// const { registerKeyword } = Ember.__loader.require("ember-htmlbars/keywords"); -// const { internal } = Ember.__loader.require('htmlbars-runtime'); -// -// registerKeyword('plugin-outlet', { -// setupState(state, env, scope, params) { -// if (!_connectorCache) { buildConnectorCache(); } -// return { outletName: env.hooks.getValue(params[0]) }; -// }, -// -// render(renderNode, env, scope, params, hash, template, inverse, visitor) { -// let state = renderNode.getState(); -// if (!state.outletName) { return true; } -// const connector = _connectorCache[state.outletName]; -// if (!connector || connector.length === 0) { return true; } -// -// const listTemplate = Ember.TEMPLATES['outlet-list']; -// listTemplate.raw.locals = ['templateId', 'outletClasses', 'tagName']; -// -// internal.hostBlock(renderNode, env, scope, listTemplate.raw, null, null, visitor, function(options) { -// connector.forEach(source => { -// const tid = source.templateId; -// options.templates.template.yieldItem(`d-outlet-${tid}`, [ -// tid, -// source.classNames, -// hash.tagName || 'div' -// ]); -// }); -// }); -// return true; -// } -// }); -// -// registerKeyword('connector', function(morph, env, scope, params, hash, template, inverse, visitor) { -// template = _templateCache[parseInt(env.hooks.getValue(hash.templateId))]; -// -// env.hooks.component(morph, -// env, -// scope, -// 'connector-container', -// params, -// hash, -// { default: template.raw, inverse }, -// visitor); -// return true; -// }); diff --git a/app/assets/javascripts/discourse/helpers/raw-plugin-outlet.js.es6 b/app/assets/javascripts/discourse/helpers/raw-plugin-outlet.js.es6 new file mode 100644 index 00000000000..ccea57e1e22 --- /dev/null +++ b/app/assets/javascripts/discourse/helpers/raw-plugin-outlet.js.es6 @@ -0,0 +1,9 @@ +import { connectorsFor } from 'discourse/lib/plugin-connectors'; + +Handlebars.registerHelper('raw-plugin-outlet', function(args) { + const connectors = connectorsFor(args.hash.name); + if (connectors.length) { + const output = connectors.map(c => c.template({context: this})); + return new Handlebars.SafeString(output.join("")); + } +}); diff --git a/app/assets/javascripts/discourse/lib/plugin-connectors.js.es6 b/app/assets/javascripts/discourse/lib/plugin-connectors.js.es6 new file mode 100644 index 00000000000..a3eb73699a7 --- /dev/null +++ b/app/assets/javascripts/discourse/lib/plugin-connectors.js.es6 @@ -0,0 +1,67 @@ +let _connectorCache; +let _extraConnectorClasses = {}; + +export function resetExtraClasses() { + _extraConnectorClasses = {}; +} + +// Note: In plugins, define a class by path and it will be wired up automatically +// eg: discourse/connectors//.js.es6 +export function extraConnectorClass(name, obj) { + _extraConnectorClasses[name] = obj; +} + +const DefaultConnectorClass = { + actions: {}, + shouldRender: () => true +}; + +function findOutlets(collection, callback) { + const disabledPlugins = Discourse.Site.currentProp('disabled_plugins') || []; + + Object.keys(collection).forEach(function(res) { + if (res.indexOf("/connectors/") !== -1) { + // Skip any disabled plugins + for (let i=0; i
@@ -20,11 +20,11 @@ {{outlet "user-card"}}
-{{plugin-outlet "above-footer"}} +{{plugin-outlet name="above-footer"}} {{#if showFooter}} {{custom-html "footer"}} {{/if}} -{{plugin-outlet "below-footer"}} +{{plugin-outlet name="below-footer"}} {{outlet "modal"}} {{topic-entrance}} diff --git a/app/assets/javascripts/discourse/templates/components/bread-crumbs.hbs b/app/assets/javascripts/discourse/templates/components/bread-crumbs.hbs index f737c969760..bbf8ef4caba 100644 --- a/app/assets/javascripts/discourse/templates/components/bread-crumbs.hbs +++ b/app/assets/javascripts/discourse/templates/components/bread-crumbs.hbs @@ -8,6 +8,6 @@ {{tag-drop firstCategory=firstCategory secondCategory=secondCategory tagId=tagId}} {{/if}} -{{plugin-outlet "bread-crumbs-right" tagName="li"}} +{{plugin-outlet name="bread-crumbs-right" connectorTagName="li"}}
diff --git a/app/assets/javascripts/discourse/templates/components/edit-category-settings.hbs b/app/assets/javascripts/discourse/templates/components/edit-category-settings.hbs index 790e61e9390..2900ab3af8f 100644 --- a/app/assets/javascripts/discourse/templates/components/edit-category-settings.hbs +++ b/app/assets/javascripts/discourse/templates/components/edit-category-settings.hbs @@ -56,7 +56,7 @@ - {{plugin-outlet "category-email-in"}} + {{plugin-outlet name="category-email-in" args=(hash category=category)}} {{/if}} {{#if showPositionInput}} @@ -82,4 +82,4 @@ {{/unless}} -{{plugin-outlet "category-custom-settings"}} +{{plugin-outlet name="category-custom-settings" args=(hash category=category)}} diff --git a/app/assets/javascripts/discourse/templates/components/navigation-bar.hbs b/app/assets/javascripts/discourse/templates/components/navigation-bar.hbs index c7d381e5679..a93e42619ee 100644 --- a/app/assets/javascripts/discourse/templates/components/navigation-bar.hbs +++ b/app/assets/javascripts/discourse/templates/components/navigation-bar.hbs @@ -2,4 +2,4 @@ {{navigation-item content=navItem filterMode=filterMode}} {{/each}} {{custom-html "extraNavItem"}} -{{plugin-outlet "extra-nav-item" tagName="li"}} +{{plugin-outlet name="extra-nav-item" connectorTagName="li"}} diff --git a/app/assets/javascripts/discourse/templates/components/plugin-outlet.hbs b/app/assets/javascripts/discourse/templates/components/plugin-outlet.hbs new file mode 100644 index 00000000000..73126a2572f --- /dev/null +++ b/app/assets/javascripts/discourse/templates/components/plugin-outlet.hbs @@ -0,0 +1,3 @@ +{{#each connectors as |c|}} + {{plugin-connector connector=c args=args class=c.classNames tagName=connectorTagName}} +{{/each}} diff --git a/app/assets/javascripts/discourse/templates/components/stream-item.hbs b/app/assets/javascripts/discourse/templates/components/stream-item.hbs index 0018f8a2d84..fed530753ef 100644 --- a/app/assets/javascripts/discourse/templates/components/stream-item.hbs +++ b/app/assets/javascripts/discourse/templates/components/stream-item.hbs @@ -6,7 +6,7 @@ {{{item.title}}}
{{category-link item.category}}
- {{plugin-outlet "user-stream-item-header"}} + {{plugin-outlet name="user-stream-item-header" args=(hash item=item)}}
{{#if actionDescription}} diff --git a/app/assets/javascripts/discourse/templates/components/topic-category.hbs b/app/assets/javascripts/discourse/templates/components/topic-category.hbs index cf717a09922..edf11686ba9 100644 --- a/app/assets/javascripts/discourse/templates/components/topic-category.hbs +++ b/app/assets/javascripts/discourse/templates/components/topic-category.hbs @@ -14,4 +14,4 @@ {{topic-featured-link topic}} {{/if}}
-{{plugin-outlet "topic-category"}} +{{plugin-outlet name="topic-category" args=(hash topic=topic category=topic.category)}} diff --git a/app/assets/javascripts/discourse/templates/components/topic-footer-buttons.hbs b/app/assets/javascripts/discourse/templates/components/topic-footer-buttons.hbs index 9585bb02364..bca64f23167 100644 --- a/app/assets/javascripts/discourse/templates/components/topic-footer-buttons.hbs +++ b/app/assets/javascripts/discourse/templates/components/topic-footer-buttons.hbs @@ -66,8 +66,12 @@ title="topic.reply.help"}} {{/if}} -{{plugin-outlet "after-topic-footer-main-buttons" tagName="span"}} +{{plugin-outlet name="after-topic-footer-main-buttons" + args=(hash topic=topic) + connectorTagName="span"}} {{pinned-button topic=topic}} {{topic-notifications-button topic=topic}} -{{plugin-outlet "after-topic-footer-buttons" tagName="span"}} +{{plugin-outlet name="after-topic-footer-buttons" + args=(hash topic=topic) + connectorTagName="span"}} diff --git a/app/assets/javascripts/discourse/templates/components/user-card-contents.hbs b/app/assets/javascripts/discourse/templates/components/user-card-contents.hbs index c88b7cc9d60..3bb893b38b8 100644 --- a/app/assets/javascripts/discourse/templates/components/user-card-contents.hbs +++ b/app/assets/javascripts/discourse/templates/components/user-card-contents.hbs @@ -30,7 +30,7 @@

{{user.title}}

{{/if}} - {{plugin-outlet "user-card-post-names"}} + {{plugin-outlet name="user-card-post-names" args=(hash user=user)}} @@ -85,7 +85,7 @@ {{/if}} - {{plugin-outlet "user-card-location-and-website"}} + {{plugin-outlet name="user-card-location-and-website" args=(hash user=user)}} {{/if}} @@ -95,7 +95,7 @@

{{i18n 'last_post'}} {{format-date user.last_posted_at leaveAgo="true"}}

{{/if}}

{{i18n 'joined'}} {{format-date user.created_at leaveAgo="true"}}

- {{plugin-outlet "user-card-metadata"}} + {{plugin-outlet name="user-card-metadata" args=(hash user=user)}} {{/if}} diff --git a/app/assets/javascripts/discourse/templates/composer.hbs b/app/assets/javascripts/discourse/templates/composer.hbs index 1a1e4524638..9e20fd73309 100644 --- a/app/assets/javascripts/discourse/templates/composer.hbs +++ b/app/assets/javascripts/discourse/templates/composer.hbs @@ -30,7 +30,7 @@ {{#if model.viewOpen}}
- {{plugin-outlet "composer-open"}} + {{plugin-outlet name="composer-open" args=(hash model=model)}}
{{{model.actionTitle}}} @@ -81,7 +81,7 @@ {{/if}}
{{/if}} - {{plugin-outlet "composer-fields"}} + {{plugin-outlet name="composer-fields" args=(hash model=model)}}
{{composer-editor topic=topic @@ -103,7 +103,7 @@ {{#if currentUser}}
- {{plugin-outlet "composer-fields-below"}} + {{plugin-outlet name="composer-fields-below" args=(hash model=model)}} {{#if canEditTags}} {{tag-chooser tags=model.tags tabIndex="4" categoryId=model.categoryId}} {{/if}} diff --git a/app/assets/javascripts/discourse/templates/discovery.hbs b/app/assets/javascripts/discourse/templates/discovery.hbs index 069be994bad..0796cbecdfe 100644 --- a/app/assets/javascripts/discourse/templates/discovery.hbs +++ b/app/assets/javascripts/discourse/templates/discovery.hbs @@ -21,11 +21,11 @@
- {{plugin-outlet "discovery-list-container-top"}} + {{plugin-outlet name="discovery-list-container-top"}} {{outlet "list-container"}}
-{{plugin-outlet "discovery-below"}} +{{plugin-outlet name="discovery-below"}} diff --git a/app/assets/javascripts/discourse/templates/full-page-search.hbs b/app/assets/javascripts/discourse/templates/full-page-search.hbs index edaf9172db9..bfeab09cfe2 100644 --- a/app/assets/javascripts/discourse/templates/full-page-search.hbs +++ b/app/assets/javascripts/discourse/templates/full-page-search.hbs @@ -94,7 +94,7 @@ {{#each result.topic.tags as |tag|}} {{discourse-tag tag}} {{/each}} - {{plugin-outlet "full-page-search-category"}} + {{plugin-outlet name="full-page-search-category" args=(hash result=result)}}
diff --git a/app/assets/javascripts/discourse/templates/list/topic-list-item.raw.hbs b/app/assets/javascripts/discourse/templates/list/topic-list-item.raw.hbs index da825c4774b..bd444a8e55c 100644 --- a/app/assets/javascripts/discourse/templates/list/topic-list-item.raw.hbs +++ b/app/assets/javascripts/discourse/templates/list/topic-list-item.raw.hbs @@ -10,7 +10,7 @@ {{#if topic.featured_link}} {{topic-featured-link topic}} {{/if}} - {{plugin-outlet "topic-list-after-title"}} + {{raw-plugin-outlet name="topic-list-after-title"}} {{#if showTopicPostBadges}} {{raw "topic-post-badges" unread=topic.unread newPosts=topic.displayNewPosts unseen=topic.unseen url=topic.lastUnreadUrl}} {{/if}} @@ -21,7 +21,7 @@ {{/each}} {{/if}} - {{plugin-outlet "topic-list-tags"}} + {{raw-plugin-outlet name="topic-list-tags"}} {{#if expandPinned}} {{raw "list/topic-excerpt" topic=topic}} {{/if}} diff --git a/app/assets/javascripts/discourse/templates/mobile/list/topic-list-item.raw.hbs b/app/assets/javascripts/discourse/templates/mobile/list/topic-list-item.raw.hbs index e630889d492..204b02323d7 100644 --- a/app/assets/javascripts/discourse/templates/mobile/list/topic-list-item.raw.hbs +++ b/app/assets/javascripts/discourse/templates/mobile/list/topic-list-item.raw.hbs @@ -37,7 +37,7 @@ {{/if}} - {{plugin-outlet "topic-list-tags"}} + {{raw-plugin-outlet name="topic-list-tags"}}
diff --git a/app/assets/javascripts/discourse/templates/modal/create-account.hbs b/app/assets/javascripts/discourse/templates/modal/create-account.hbs index 7921b2a2452..bdaa3d82394 100644 --- a/app/assets/javascripts/discourse/templates/modal/create-account.hbs +++ b/app/assets/javascripts/discourse/templates/modal/create-account.hbs @@ -52,7 +52,11 @@ {{/if}} - {{plugin-outlet "create-account-before-password"}} + {{plugin-outlet name="create-account-before-password" + args=(hash accountName=accountName + accountUsername=accountUsername + accountPassword=accountPassword + userFields=userFields)}} {{#if passwordRequired}} diff --git a/app/assets/javascripts/discourse/templates/modal/history.hbs b/app/assets/javascripts/discourse/templates/modal/history.hbs index ce860fefcbf..9714e004096 100644 --- a/app/assets/javascripts/discourse/templates/modal/history.hbs +++ b/app/assets/javascripts/discourse/templates/modal/history.hbs @@ -94,7 +94,7 @@
{{/if}} - {{plugin-outlet "post-revisions"}} + {{plugin-outlet name="post-revisions" args=(hash model=model)}} {{#links-redirect class="row"}} {{{bodyDiff}}} diff --git a/app/assets/javascripts/discourse/templates/preferences.hbs b/app/assets/javascripts/discourse/templates/preferences.hbs index 2afbb4d9869..3f39e111fd6 100644 --- a/app/assets/javascripts/discourse/templates/preferences.hbs +++ b/app/assets/javascripts/discourse/templates/preferences.hbs @@ -248,7 +248,7 @@ {{preference-checkbox labelKey="user.enable_quoting" checked=model.user_option.enable_quoting}} {{preference-checkbox labelKey="user.dynamic_favicon" checked=model.user_option.dynamic_favicon}} {{preference-checkbox labelKey="user.disable_jump_reply" checked=model.user_option.disable_jump_reply}} - {{plugin-outlet "user-custom-preferences"}} + {{plugin-outlet name="user-custom-preferences" args=(hash model=model)}}
@@ -350,7 +350,7 @@
{{/if}} - {{plugin-outlet "user-custom-controls"}} + {{plugin-outlet name="user-custom-controls" args=(hash model=model)}}
diff --git a/app/assets/javascripts/discourse/templates/static.hbs b/app/assets/javascripts/discourse/templates/static.hbs index 529b5ba149e..c535f16fb35 100644 --- a/app/assets/javascripts/discourse/templates/static.hbs +++ b/app/assets/javascripts/discourse/templates/static.hbs @@ -1,7 +1,7 @@ {{#d-section bodyClass=bodyClass class="container"}} {{#watch-read action="markFaqRead" path=model.path}}
- {{plugin-outlet "above-static"}} + {{plugin-outlet name="above-static"}} {{{model.html}}} {{#if showSignupButton}} diff --git a/app/assets/javascripts/discourse/templates/tags/show.hbs b/app/assets/javascripts/discourse/templates/tags/show.hbs index 9cf29e587af..4b33995216c 100644 --- a/app/assets/javascripts/discourse/templates/tags/show.hbs +++ b/app/assets/javascripts/discourse/templates/tags/show.hbs @@ -42,7 +42,7 @@
-{{plugin-outlet "discovery-list-container-top"}} +{{plugin-outlet name="discovery-list-container-top"}}
{{conditional-loading-spinner condition=loading}} diff --git a/app/assets/javascripts/discourse/templates/topic.hbs b/app/assets/javascripts/discourse/templates/topic.hbs index ffbfdab6de4..e21c2e18809 100644 --- a/app/assets/javascripts/discourse/templates/topic.hbs +++ b/app/assets/javascripts/discourse/templates/topic.hbs @@ -6,7 +6,7 @@
{{/if}} - {{plugin-outlet "topic-above-post-stream"}} + {{plugin-outlet name="topic-above-post-stream" args=(hash model=model)}} {{#if model.postStream.loaded}} {{#if model.postStream.firstPostPresent}} @@ -30,7 +30,7 @@ {{tag-chooser tags=buffered.tags categoryId=buffered.category_id}} {{/if}} - {{plugin-outlet "edit-topic"}} + {{plugin-outlet name="edit-topic" args=(hash model=model buffered=buffered)}} {{d-button action="finishedEditingTopic" class="btn-primary btn-small submit-edit" icon="check"}} {{d-button action="cancelEditingTopic" class="btn-small cancel-edit" icon="times"}} @@ -59,7 +59,7 @@ {{/unless}} {{/if}} - {{plugin-outlet "topic-title"}} + {{plugin-outlet name="topic-title" args=(hash model=model)}} {{/if}} @@ -125,7 +125,7 @@
{{conditional-loading-spinner condition=model.postStream.loadingAbove}} - {{plugin-outlet "topic-above-posts"}} + {{plugin-outlet name="topic-above-posts" args=(hash model=model)}} {{#unless model.postStream.loadingFilter}} {{scrolling-post-stream @@ -221,7 +221,7 @@
{{/if}} - {{plugin-outlet "topic-above-suggested"}} + {{plugin-outlet name="topic-above-suggested" args=(hash model=model)}} {{#if model.details.suggested_topics.length}}
diff --git a/app/assets/javascripts/discourse/templates/user.hbs b/app/assets/javascripts/discourse/templates/user.hbs index 64a5b2583a5..5d047d296ad 100644 --- a/app/assets/javascripts/discourse/templates/user.hbs +++ b/app/assets/javascripts/discourse/templates/user.hbs @@ -47,7 +47,9 @@ {{#if currentUser.staff}}
  • {{fa-icon "wrench"}}{{i18n 'admin.user.show_admin_profile'}}
  • {{/if}} - {{plugin-outlet "user-profile-controls" tagName="li"}} + {{plugin-outlet name="user-profile-controls" + connectorTagName="li" + args=(hash model=model)}} {{#if collapsedInfo}} {{#if viewingSelf}} @@ -75,7 +77,7 @@ {{model.website_name}} {{/if}} {{/if}} - {{plugin-outlet "user-location-and-website"}} + {{plugin-outlet name="user-location-and-website" args=(hash model=model)}}
    @@ -102,12 +104,13 @@ {{/if}} {{/each}} - {{plugin-outlet "user-profile-public-fields"}} + {{plugin-outlet name="user-profile-public-fields" + args=(hash publicUserFields=publicUserFields + model=model)}}
    {{/if}} - {{plugin-outlet "user-profile-primary"}} - + {{plugin-outlet name="user-profile-primary" args=(hash model=model)}}
    @@ -153,7 +156,7 @@ {{d-button action="adminDelete" icon="exclamation-triangle" label="user.admin_delete" class="btn-danger"}} {{/if}} - {{plugin-outlet "user-profile-secondary"}} + {{plugin-outlet name="user-profile-secondary" args=(hash model=model)}} {{/unless}} diff --git a/app/assets/javascripts/discourse/templates/user/activity.hbs b/app/assets/javascripts/discourse/templates/user/activity.hbs index f1818f2ec9a..b0fa84ba144 100644 --- a/app/assets/javascripts/discourse/templates/user/activity.hbs +++ b/app/assets/javascripts/discourse/templates/user/activity.hbs @@ -23,7 +23,9 @@ {{/link-to}} {{/if}} - {{plugin-outlet "user-activity-bottom" tagName='li'}} + {{plugin-outlet name="user-activity-bottom" + connectorTagName='li' + args=(hash model=model)}} {{/mobile-nav}} {{#if viewingSelf}} diff --git a/app/assets/javascripts/discourse/templates/user/summary.hbs b/app/assets/javascripts/discourse/templates/user/summary.hbs index e36928a986a..ceae695ecb1 100644 --- a/app/assets/javascripts/discourse/templates/user/summary.hbs +++ b/app/assets/javascripts/discourse/templates/user/summary.hbs @@ -37,7 +37,9 @@
  • {{user-stat value=model.likes_received label="user.summary.likes_received"}}
  • - {{plugin-outlet "user-summary-stat" tagName="li"}} + {{plugin-outlet name="user-summary-stat" + connectorTagName="li" + args=(hash model=model)}} diff --git a/test/javascripts/acceptance/plugin-outlet-connector-class-test.js.es6 b/test/javascripts/acceptance/plugin-outlet-connector-class-test.js.es6 new file mode 100644 index 00000000000..82b34f7ca7c --- /dev/null +++ b/test/javascripts/acceptance/plugin-outlet-connector-class-test.js.es6 @@ -0,0 +1,47 @@ +import { acceptance } from "helpers/qunit-helpers"; +import { extraConnectorClass } from 'discourse/lib/plugin-connectors'; + +const PREFIX = "javascripts/single-test/connectors"; +acceptance("Plugin Outlet - Connector Class", { + setup() { + extraConnectorClass('user-profile-primary/hello', { + actions: { + sayHello() { + this.set('hello', 'hello!'); + } + } + }); + + extraConnectorClass('user-profile-primary/dont-render', { + shouldRender(args) { + return args.model.get('username') !== 'eviltrout'; + } + }); + + Ember.TEMPLATES[`${PREFIX}/user-profile-primary/hello`] = Ember.HTMLBars.compile( + `{{model.username}} + + {{hello}}` + ); + Ember.TEMPLATES[`${PREFIX}/user-profile-primary/dont-render`] = Ember.HTMLBars.compile( + `I'm not rendered!` + ); + }, + + teardown() { + delete Ember.TEMPLATES[`${PREFIX}/user-profile-primary/hello`]; + delete Ember.TEMPLATES[`${PREFIX}/user-profile-primary/dont-render`]; + } +}); + +test("Renders a template into the outlet", assert => { + visit("/users/eviltrout"); + andThen(() => { + assert.ok(find('.user-profile-primary-outlet.hello').length === 1, 'it has class names'); + assert.ok(!find('.user-profile-primary-outlet.dont-render').length, "doesn't render"); + }); + click('.say-hello'); + andThen(() => { + assert.equal(find('.hello-result').text(), 'hello!', 'actions delegate properly'); + }); +}); diff --git a/test/javascripts/acceptance/plugin-outlet-multi-template-test.js.es6 b/test/javascripts/acceptance/plugin-outlet-multi-template-test.js.es6 index 34d5bc00459..0379b2d8e54 100644 --- a/test/javascripts/acceptance/plugin-outlet-multi-template-test.js.es6 +++ b/test/javascripts/acceptance/plugin-outlet-multi-template-test.js.es6 @@ -1,5 +1,5 @@ import { acceptance } from "helpers/qunit-helpers"; -import { clearCache } from 'discourse/helpers/plugin-outlet'; +import { clearCache } from 'discourse/lib/plugin-connectors'; const HELLO = 'javascripts/multi-test/connectors/user-profile-primary/hello'; const GOODBYE = 'javascripts/multi-test/connectors/user-profile-primary/goodbye'; diff --git a/test/javascripts/acceptance/plugin-outlet-single-template-test.js.es6 b/test/javascripts/acceptance/plugin-outlet-single-template-test.js.es6 index 228506e27c9..ee236ed8518 100644 --- a/test/javascripts/acceptance/plugin-outlet-single-template-test.js.es6 +++ b/test/javascripts/acceptance/plugin-outlet-single-template-test.js.es6 @@ -4,9 +4,7 @@ const CONNECTOR = 'javascripts/single-test/connectors/user-profile-primary/hello acceptance("Plugin Outlet - Single Template", { setup() { Ember.TEMPLATES[CONNECTOR] = Ember.HTMLBars.compile( - `{{model.username}} - - {{model.email}}` + `{{model.username}}` ); }, @@ -21,8 +19,4 @@ test("Renders a template into the outlet", assert => { assert.ok(find('.user-profile-primary-outlet.hello').length === 1, 'it has class names'); assert.equal(find('.hello-username').text(), 'eviltrout', 'it renders into the outlet'); }); - click('.hello-check-email'); - andThen(() => { - assert.equal(find('.hello-email').text(), 'eviltrout@example.com', 'actions delegate properly'); - }); }); diff --git a/test/javascripts/helpers/qunit-helpers.js.es6 b/test/javascripts/helpers/qunit-helpers.js.es6 index d8351405f0c..528b537de0b 100644 --- a/test/javascripts/helpers/qunit-helpers.js.es6 +++ b/test/javascripts/helpers/qunit-helpers.js.es6 @@ -5,9 +5,10 @@ import siteFixtures from 'fixtures/site-fixtures'; import HeaderComponent from 'discourse/components/site-header'; import { forceMobile, resetMobile } from 'discourse/lib/mobile'; import { resetPluginApi } from 'discourse/lib/plugin-api'; -import { clearCache as clearOutletCache } from 'discourse/helpers/plugin-outlet'; +import { clearCache as clearOutletCache, resetExtraClasses } from 'discourse/lib/plugin-connectors'; import { clearHTMLCache } from 'discourse/helpers/custom-html'; + function currentUser() { return Discourse.User.create(sessionFixtures['/session/current.json'].current_user); } @@ -44,6 +45,7 @@ function acceptance(name, options) { // For now don't do scrolling stuff in Test Mode HeaderComponent.reopen({examineDockHeader: Ember.K}); + resetExtraClasses(); const siteJson = siteFixtures['site.json'].site; if (options) { if (options.setup) { @@ -80,6 +82,7 @@ function acceptance(name, options) { Discourse.User.resetCurrent(); Discourse.Site.resetCurrent(Discourse.Site.create(jQuery.extend(true, {}, fixtures['site.json'].site))); + resetExtraClasses(); clearOutletCache(); clearHTMLCache(); resetPluginApi();