From 465f1c472cff1f6b6eab04700a396d2e3765b5c1 Mon Sep 17 00:00:00 2001 From: Mike Taylor Date: Thu, 26 Mar 2015 15:31:44 +0000 Subject: [PATCH] Part of ACREP-22. Add a new helper, mkws-if-either, which we need in order to test whether we have either of the md-free_to_read or md-license_url fields. Astonishingly, there is no way to make such a check using stock Handlebars. --- src/mkws-handlebars.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/mkws-handlebars.js b/src/mkws-handlebars.js index bd9af8d..7e5c0e0 100644 --- a/src/mkws-handlebars.js +++ b/src/mkws-handlebars.js @@ -104,3 +104,15 @@ Handlebars.registerHelper('mkws-repeat', function(count, options) { } return out; }); + +// Ridiculous that Handlebars has no way to do "or" +Handlebars.registerHelper('mkws-if-either', function(cond1, cond2, options) { + if (typeof cond1 === 'function') { cond1 = cond1.call(this); } + if (typeof cond2 === 'function') { cond2 = cond2.call(this); } + + if (cond1 || cond2) { + return options.fn(this); + } else { + return options.inverse(this); + } +}); -- 1.7.10.4