Framework for supporting Ember 1.12/1.13 helpers simulataneously
This commit is contained in:
parent
750338954c
commit
bd352385a5
|
@ -13,8 +13,24 @@ export function htmlHelper(fn) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const _helpers = {};
|
||||||
|
|
||||||
export function registerHelper(name, fn) {
|
export function registerHelper(name, fn) {
|
||||||
Ember.HTMLBars._registerHelper(name, fn);
|
if (Ember.Helper) {
|
||||||
|
_helpers[name] = Ember.Helper.helper(fn);
|
||||||
|
} else {
|
||||||
|
return Ember.HTMLBars._registerHelper(name, fn);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export function findHelper(name) {
|
||||||
|
return _helpers[name];
|
||||||
|
}
|
||||||
|
|
||||||
|
export function registerHelpers(registry) {
|
||||||
|
Object.keys(_helpers).forEach(name => {
|
||||||
|
registry.register(`helper:${name}`, _helpers[name], { singleton: false });
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function resolveParams(ctx, options) {
|
function resolveParams(ctx, options) {
|
||||||
|
@ -39,6 +55,13 @@ function resolveParams(ctx, options) {
|
||||||
}
|
}
|
||||||
|
|
||||||
export function registerUnbound(name, fn) {
|
export function registerUnbound(name, fn) {
|
||||||
|
if (Ember.Helper) {
|
||||||
|
_helpers[name] = Ember.Helper.helper(function() {
|
||||||
|
// TODO: Allow newer ember to use helpers
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const func = function(property, options) {
|
const func = function(property, options) {
|
||||||
if (options.types && (options.types[0] === "ID" || options.types[0] === "PathExpression")) {
|
if (options.types && (options.types[0] === "ID" || options.types[0] === "PathExpression")) {
|
||||||
property = get(this, property, options);
|
property = get(this, property, options);
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
/* global requirejs, require */
|
import { findHelper } from 'discourse-common/lib/helpers';
|
||||||
|
|
||||||
|
/* global requirejs, require */
|
||||||
var classify = Ember.String.classify;
|
var classify = Ember.String.classify;
|
||||||
var get = Ember.get;
|
var get = Ember.get;
|
||||||
|
|
||||||
|
@ -109,7 +110,9 @@ export function buildResolver(baseName) {
|
||||||
},
|
},
|
||||||
|
|
||||||
resolveHelper(parsedName) {
|
resolveHelper(parsedName) {
|
||||||
return this.customResolve(parsedName) || this._super(parsedName);
|
return findHelper(parsedName.fullNameWithoutType) ||
|
||||||
|
this.customResolve(parsedName) ||
|
||||||
|
this._super(parsedName);
|
||||||
},
|
},
|
||||||
|
|
||||||
resolveController(parsedName) {
|
resolveController(parsedName) {
|
||||||
|
|
|
@ -20,15 +20,7 @@ export function setCustomHTML(key, html) {
|
||||||
_customizations[key] = html;
|
_customizations[key] = html;
|
||||||
}
|
}
|
||||||
|
|
||||||
registerHelper('custom-html', function(params, hash, options, env) {
|
registerHelper('custom-html', function(params) {
|
||||||
const name = params[0];
|
const html = getCustomHTML(params[0]);
|
||||||
const html = getCustomHTML(name);
|
|
||||||
if (html) { return html; }
|
if (html) { return html; }
|
||||||
|
|
||||||
const contextString = params[1];
|
|
||||||
const target = (env || contextString);
|
|
||||||
const container = target.container || target.data.view.container;
|
|
||||||
if (container.lookup('template:' + name)) {
|
|
||||||
return env.helpers.partial.helperFunction.apply(this, arguments);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
|
@ -29,17 +29,6 @@
|
||||||
|
|
||||||
And it will be wired up automatically.
|
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}}
|
|
||||||
```
|
|
||||||
|
|
||||||
## Disabling
|
## Disabling
|
||||||
|
|
||||||
If a plugin returns a disabled status, the outlets will not be wired up for it.
|
If a plugin returns a disabled status, the outlets will not be wired up for it.
|
||||||
|
@ -174,13 +163,6 @@ registerHelper('plugin-outlet', function(params, hash, options, env) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (options.isBlock) {
|
|
||||||
const virtualView = Ember.View.extend({
|
|
||||||
isVirtual: true,
|
|
||||||
tagName: hash.tagName || '',
|
|
||||||
template: options.template
|
|
||||||
});
|
|
||||||
env.helpers.view.helperFunction.call(this, [virtualView], hash, options, env);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,6 @@
|
||||||
export function autoLoadModules() {
|
import { registerHelpers } from 'discourse-common/lib/helpers';
|
||||||
|
|
||||||
|
export function autoLoadModules(container, registry) {
|
||||||
Object.keys(requirejs.entries).forEach(entry => {
|
Object.keys(requirejs.entries).forEach(entry => {
|
||||||
if ((/\/helpers\//).test(entry)) {
|
if ((/\/helpers\//).test(entry)) {
|
||||||
require(entry, null, null, true);
|
require(entry, null, null, true);
|
||||||
|
@ -7,6 +9,7 @@ export function autoLoadModules() {
|
||||||
require(entry, null, null, true);
|
require(entry, null, null, true);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
registerHelpers(registry);
|
||||||
}
|
}
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
|
|
|
@ -1,11 +1,14 @@
|
||||||
|
import { registerHelpers } from 'discourse-common/lib/helpers';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'load-helpers',
|
name: 'load-helpers',
|
||||||
|
|
||||||
initialize() {
|
initialize(container, registry) {
|
||||||
Object.keys(requirejs.entries).forEach(entry => {
|
Object.keys(requirejs.entries).forEach(entry => {
|
||||||
if ((/\/helpers\//).test(entry)) {
|
if ((/\/helpers\//).test(entry)) {
|
||||||
require(entry, null, null, true);
|
require(entry, null, null, true);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
registerHelpers(registry);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue