Add a handlebars helper for variadic compound AND conditions.

e.g., from a comment in the commit:

// Execute the conditional code if all conditions are true.
// Example usage:
//     {{#if_and cond1 cond2 cond3}}
//         <p>All true</p>
//     {{/if_and}}

We'll use this for the email forwarding UI, but it may also be
generally useful, and easy to generalize to OR.

(imported from commit da601f94d9da300213ff46be50255135c014eca0)
This commit is contained in:
Jessica McKellar 2013-08-13 12:08:12 -04:00
parent 15afdf65eb
commit f7784a2f1d
1 changed files with 16 additions and 0 deletions

View File

@ -35,6 +35,22 @@ $(function () {
Handlebars.registerHelper('plural', function (condition, one, other) {
return (condition === 1) ? one : other;
});
Handlebars.registerHelper('if_and', function () {
// Execute the conditional code if all conditions are true.
// Example usage:
// {{#if_and cond1 cond2 cond3}}
// <p>All true</p>
// {{/if_and}}
var options = arguments[arguments.length - 1];
var i;
for (i = 0; i < arguments.length - 1; i++) {
if (!arguments[i]) {
return options.inverse(this);
}
}
return options.fn(this);
});
});
return exports;