mirror of
https://github.com/discourse/discourse.git
synced 2025-09-06 10:50:21 +08:00
32 lines
801 B
JavaScript
32 lines
801 B
JavaScript
const get = Discourse.EmberCompatHandlebars.get;
|
|
|
|
function resolveParams(ctx, options) {
|
|
let params = {};
|
|
const hash = options.hash;
|
|
|
|
if (hash) {
|
|
if (options.hashTypes) {
|
|
Ember.keys(hash).forEach(function(k) {
|
|
const type = options.hashTypes[k];
|
|
if (type === "STRING") {
|
|
params[k] = hash[k];
|
|
} else if (type === "ID") {
|
|
params[k] = get(ctx, hash[k], options);
|
|
}
|
|
});
|
|
} else {
|
|
params = hash;
|
|
}
|
|
}
|
|
return params;
|
|
}
|
|
|
|
export default function registerUnbound(name, fn) {
|
|
Handlebars.registerHelper(name, function(property, options) {
|
|
if (options.types && options.types[0] === "ID") {
|
|
property = get(this, property, options);
|
|
}
|
|
|
|
return fn.call(this, property, resolveParams(this, options));
|
|
});
|
|
}
|