Skip to content

Commit

Permalink
feat: add {{debug x}} handler
Browse files Browse the repository at this point in the history
  • Loading branch information
UnderKoen committed Oct 8, 2024
1 parent 0b24fe0 commit 05db1aa
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
11 changes: 11 additions & 0 deletions packages/loot-core/src/server/accounts/rules.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,17 @@ describe('Action', () => {
testHelper('{{year "2002-07-25"}}', '2002');
testHelper('{{format "2002-07-25" "MM yyyy d"}}', '07 2002 25');
});

test('{{debug}} should log the item', () => {
const action = new Action('set', 'notes', '', {
template: '{{debug notes}}',
});
const item = { notes: 'Sarah' };
const spy = jest.spyOn(console, 'log').mockImplementation();
action.exec(item);
expect(spy).toHaveBeenCalledWith('Sarah');
spy.mockRestore();
});
});
});

Expand Down
3 changes: 3 additions & 0 deletions packages/loot-core/src/server/accounts/rules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ function registerHandlebarsHelpers() {
month: (date: string) => format(date, 'M'),
year: (date: string) => format(date, 'yyyy'),
format: (date: string, f: string) => format(date, f),
debug: (value: unknown) => {
console.log(value);
},
};

for (const [name, fn] of Object.entries(helpers)) {
Expand Down

0 comments on commit 05db1aa

Please sign in to comment.