Skip to content

Commit

Permalink
fix: update handlebars or template to not ignore first param (#30)
Browse files Browse the repository at this point in the history
  • Loading branch information
btkostner authored Oct 18, 2023
1 parent 78ac2c0 commit 91d84af
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
11 changes: 11 additions & 0 deletions src/handlebars.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,15 @@ describe.concurrent("handlebars", () => {

expect(result).toEqual("helpers: false");
});

it("can use an or helper without an else statement", async (ctx) => {
const template = Handlebars.compile(
"{{#or POSTGRES_VERSION KAFKA_USAGE}} services:{{/or}}"
);
const result = template({
POSTGRES_VERSION: "14"
});

expect(result).toEqual(" services:");
});
});
6 changes: 3 additions & 3 deletions src/handlebars.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import Handlebars from "handlebars";
import isObject from "lodash/isObject";

Handlebars.registerHelper("or", function (context, ...params) {
Handlebars.registerHelper("or", function (...params) {
const options = params[params.length - 1];
params.pop();

for (const value of params) {
if (value) {
return options.fn(context);
return options.fn();
}
}

return options.inverse(context);
return options.inverse();
});

export default Handlebars;

0 comments on commit 91d84af

Please sign in to comment.