Backwards compatible support for inline helpers

This commit is contained in:
Robin Ward 2016-10-28 12:48:56 -04:00
parent 319b043f43
commit 1e4a56fe14
4 changed files with 14 additions and 13 deletions

View File

@ -1,13 +1,14 @@
import { get } from 'discourse-common/lib/raw-handlebars'; 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 // `Ember.Helper` is only available in versions after 1.12
export function htmlHelper(fn) { export function htmlHelper(fn) {
if (Ember.Helper) { if (Ember.Helper) {
return Ember.Helper.helper(function(...args) { return Ember.Helper.helper(function(...args) {
if (args.length > 1) { return new Handlebars.SafeString(fn.apply(this, fixArgs(args)) || '');
args = args[0].concat(args[args.length-1]);
}
return new Handlebars.SafeString(fn.apply(this, args) || '');
}); });
} else { } else {
return Ember.Handlebars.makeBoundHelper(function() { return Ember.Handlebars.makeBoundHelper(function() {

View File

@ -20,7 +20,7 @@ export function setCustomHTML(key, html) {
_customizations[key] = html; _customizations[key] = html;
} }
registerHelper('custom-html', function(params) { registerHelper('custom-html', function([id]) {
const html = getCustomHTML(params[0]); const html = getCustomHTML(id);
if (html) { return html; } if (html) { return html; }
}); });

View File

@ -1,6 +1,8 @@
import { relativeAge } from 'discourse/lib/formatter'; import { relativeAge } from 'discourse/lib/formatter';
import { registerHelper } from 'discourse-common/lib/helpers';
export default function(dt, params) { registerHelper('inline-date', function([dt]) {
dt = params.data.view.getStream(dt).value(); // TODO: Remove this in 1.13 or greater
if (dt.value) { dt = dt.value(); }
return relativeAge(new Date(dt)); return relativeAge(new Date(dt));
} });

View File

@ -118,7 +118,7 @@ function viewInjections(container) {
} }
// unbound version of outlets, only has a template // unbound version of outlets, only has a template
Handlebars.registerHelper('plugin-outlet', function(name){ Handlebars.registerHelper('plugin-outlet', function(name) {
if (!_rawCache) { buildConnectorCache(); } if (!_rawCache) { buildConnectorCache(); }
const functions = _rawCache[name]; const functions = _rawCache[name];
@ -134,9 +134,7 @@ Handlebars.registerHelper('plugin-outlet', function(name){
}); });
registerHelper('plugin-outlet', function(params, hash, options, env) { registerHelper('plugin-outlet', function([connectionName], hash, options, env) {
const connectionName = params[0];
if (!_connectorCache) { buildConnectorCache(); } if (!_connectorCache) { buildConnectorCache(); }
if (_connectorCache[connectionName]) { if (_connectorCache[connectionName]) {