Backwards compatible support for inline helpers
This commit is contained in:
parent
319b043f43
commit
1e4a56fe14
|
@ -1,13 +1,14 @@
|
|||
import { get } from 'discourse-common/lib/raw-handlebars';
|
||||
|
||||
function fixArgs(args) {
|
||||
return (args.length > 1) ? args[0].concat(args[args.length-1]) : args;
|
||||
}
|
||||
|
||||
// `Ember.Helper` is only available in versions after 1.12
|
||||
export function htmlHelper(fn) {
|
||||
if (Ember.Helper) {
|
||||
return Ember.Helper.helper(function(...args) {
|
||||
if (args.length > 1) {
|
||||
args = args[0].concat(args[args.length-1]);
|
||||
}
|
||||
return new Handlebars.SafeString(fn.apply(this, args) || '');
|
||||
return new Handlebars.SafeString(fn.apply(this, fixArgs(args)) || '');
|
||||
});
|
||||
} else {
|
||||
return Ember.Handlebars.makeBoundHelper(function() {
|
||||
|
|
|
@ -20,7 +20,7 @@ export function setCustomHTML(key, html) {
|
|||
_customizations[key] = html;
|
||||
}
|
||||
|
||||
registerHelper('custom-html', function(params) {
|
||||
const html = getCustomHTML(params[0]);
|
||||
registerHelper('custom-html', function([id]) {
|
||||
const html = getCustomHTML(id);
|
||||
if (html) { return html; }
|
||||
});
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
import { relativeAge } from 'discourse/lib/formatter';
|
||||
import { registerHelper } from 'discourse-common/lib/helpers';
|
||||
|
||||
export default function(dt, params) {
|
||||
dt = params.data.view.getStream(dt).value();
|
||||
registerHelper('inline-date', function([dt]) {
|
||||
// TODO: Remove this in 1.13 or greater
|
||||
if (dt.value) { dt = dt.value(); }
|
||||
return relativeAge(new Date(dt));
|
||||
}
|
||||
});
|
||||
|
|
|
@ -118,7 +118,7 @@ function viewInjections(container) {
|
|||
}
|
||||
|
||||
// unbound version of outlets, only has a template
|
||||
Handlebars.registerHelper('plugin-outlet', function(name){
|
||||
Handlebars.registerHelper('plugin-outlet', function(name) {
|
||||
if (!_rawCache) { buildConnectorCache(); }
|
||||
|
||||
const functions = _rawCache[name];
|
||||
|
@ -134,9 +134,7 @@ Handlebars.registerHelper('plugin-outlet', function(name){
|
|||
|
||||
});
|
||||
|
||||
registerHelper('plugin-outlet', function(params, hash, options, env) {
|
||||
const connectionName = params[0];
|
||||
|
||||
registerHelper('plugin-outlet', function([connectionName], hash, options, env) {
|
||||
if (!_connectorCache) { buildConnectorCache(); }
|
||||
|
||||
if (_connectorCache[connectionName]) {
|
||||
|
|
Loading…
Reference in New Issue