This will sort of work:
Ember.Handlebars.helper('chain', function() {
var that = this,
helpers = [],
current = null,
options = arguments[arguments.length - 1];
for (var i = 0; i < arguments.length - 1; i++) {
var arg = arguments[i],
helperFn = Ember.Handlebars.helpers[arg];
if (helperFn) {
current = {
fn: helperFn,
args: []
};
helpers.push(current);
}
else if (current) {
current.args.push(arg);
}
else {
throw new Error("Unknown helper: " + arg);
}
}
var prevResult = null;
$.each(helpers, function (index, helper) {
var args = helper.args.concat(options),
before = options.data.buffer.buffer;
if (prevResult) {
args.unshift(prevResult);
}
helper.fn.apply(that, args);
var after = options.data.buffer.buffer;
prevResult = after.slice(before.length).replace(/<\/?script[^>]*>/g, "");
if (index < helpers.length - 1) {
options.data.buffer.buffer = before;
}
});
});
The problem is, handlebars helpers don't really return a value. Instead, they write directly into the buffer provided through options argument. In the example above, I directly manipulate this buffer to extract product of one helper and insert it as the first argument of the next helper (stripping out ember metatags is just a bonus of WTF-ery).
As you can see, it works in this simple use case, but will probably break for anything more involved. Handlebars helpers just weren't designed to be used as functions.