var templates = (function () {

var exports = {};

exports.render = function (name, arg) {
    if (Handlebars.templates === undefined) {
        Handlebars.templates = {};
    }

    if (Handlebars.templates[name] === undefined) {
        // Fetch the template using a synchronous AJAX request.
        //
        // This is only for local development.  In prod we precompile
        // templates and serve JavaScript which will have already
        // populated Handlebars.templates.
        $.ajax({
            url:     '/static/templates/'+name+'.handlebars?' + new Date().getTime(),
            async:   false,
            success: function (data) {
                Handlebars.templates[name] = Handlebars.compile(data);
            }
        });
    }

    return Handlebars.templates[name](arg);
};

$(function () {
    // Regular Handlebars partials require pre-registering.  This allows us
    // to treat any template as a partial.
    Handlebars.registerHelper('partial', function (template_name, context) {
        return new Handlebars.SafeString(exports.render(template_name, this));
    });

    Handlebars.registerHelper('plural', function (condition, one, other) {
        return (condition === 1) ? one : other;
    });
});

return exports;
}());

var templates = (function () {

var exports = {};

exports.render = function (name, arg) {
    if (Handlebars.templates === undefined) {
        Handlebars.templates = {};
    }

    if (Handlebars.templates[name] === undefined) {
        // Fetch the template using a synchronous AJAX request.
        //
        // This is only for local development.  In prod we precompile
        // templates and serve JavaScript which will have already
        // populated Handlebars.templates.
        $.ajax({
            url:     '/static/templates/'+name+'.handlebars?' + new Date().getTime(),
            async:   false,
            success: function (data) {
                Handlebars.templates[name] = Handlebars.compile(data);
            }
        });
    }

    return Handlebars.templates[name](arg);
};

$(function () {
    // Regular Handlebars partials require pre-registering.  This allows us
    // to treat any template as a partial.
    Handlebars.registerHelper('partial', function (template_name, context) {
        return new Handlebars.SafeString(exports.render(template_name, this));
    });

    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;
}());

Add a handlebars helper for variadic compound AND conditions.
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)
