diff options
Diffstat (limited to 'lib/mail/mailer.ts')
| -rw-r--r-- | lib/mail/mailer.ts | 146 |
1 files changed, 102 insertions, 44 deletions
diff --git a/lib/mail/mailer.ts b/lib/mail/mailer.ts index 61201e99..0387d7dd 100644 --- a/lib/mail/mailer.ts +++ b/lib/mail/mailer.ts @@ -23,54 +23,96 @@ function registerHandlebarsHelpers() { return i18next.t(key, options.hash || {}); }); - // eq 헬퍼 등록 - 두 값을 비교 (블록 헬퍼) - handlebars.registerHelper('eq', function(a: any, b: any, options: any) { - if (a === b) { - return options.fn(this); - } else { - return options.inverse(this); + // eq 헬퍼 등록 - 인라인과 블록 헬퍼 둘 다 지원 + handlebars.registerHelper('eq', function(a: any, b: any, options?: any) { + const result = a === b; + + // 블록 헬퍼로 사용된 경우 (options가 있고 fn 함수가 있는 경우) + if (options && typeof options.fn === 'function') { + if (result) { + return options.fn(this); + } else { + return options.inverse(this); + } } + + // 인라인 헬퍼로 사용된 경우 + return result; }); - // 기타 유용한 헬퍼들 - handlebars.registerHelper('ne', function(a: any, b: any, options: any) { - if (a !== b) { - return options.fn(this); - } else { - return options.inverse(this); + // ne 헬퍼 - 인라인과 블록 헬퍼 둘 다 지원 + handlebars.registerHelper('ne', function(a: any, b: any, options?: any) { + const result = a !== b; + + if (options && typeof options.fn === 'function') { + if (result) { + return options.fn(this); + } else { + return options.inverse(this); + } } + + return result; }); - handlebars.registerHelper('gt', function(a: any, b: any, options: any) { - if (a > b) { - return options.fn(this); - } else { - return options.inverse(this); + // gt 헬퍼 - 인라인과 블록 헬퍼 둘 다 지원 + handlebars.registerHelper('gt', function(a: any, b: any, options?: any) { + const result = a > b; + + if (options && typeof options.fn === 'function') { + if (result) { + return options.fn(this); + } else { + return options.inverse(this); + } } + + return result; }); - handlebars.registerHelper('gte', function(a: any, b: any, options: any) { - if (a >= b) { - return options.fn(this); - } else { - return options.inverse(this); + // gte 헬퍼 - 인라인과 블록 헬퍼 둘 다 지원 + handlebars.registerHelper('gte', function(a: any, b: any, options?: any) { + const result = a >= b; + + if (options && typeof options.fn === 'function') { + if (result) { + return options.fn(this); + } else { + return options.inverse(this); + } } + + return result; }); - handlebars.registerHelper('lt', function(a: any, b: any, options: any) { - if (a < b) { - return options.fn(this); - } else { - return options.inverse(this); + // lt 헬퍼 - 인라인과 블록 헬퍼 둘 다 지원 + handlebars.registerHelper('lt', function(a: any, b: any, options?: any) { + const result = a < b; + + if (options && typeof options.fn === 'function') { + if (result) { + return options.fn(this); + } else { + return options.inverse(this); + } } + + return result; }); - handlebars.registerHelper('lte', function(a: any, b: any, options: any) { - if (a <= b) { - return options.fn(this); - } else { - return options.inverse(this); + // lte 헬퍼 - 인라인과 블록 헬퍼 둘 다 지원 + handlebars.registerHelper('lte', function(a: any, b: any, options?: any) { + const result = a <= b; + + if (options && typeof options.fn === 'function') { + if (result) { + return options.fn(this); + } else { + return options.inverse(this); + } } + + return result; }); // and 헬퍼 - 모든 조건이 true인지 확인 (블록 헬퍼) @@ -78,12 +120,17 @@ function registerHandlebarsHelpers() { // 마지막 인자는 Handlebars 옵션 const options = args[args.length - 1]; const values = args.slice(0, -1); + const result = values.every(Boolean); - if (values.every(Boolean)) { - return options.fn(this); - } else { - return options.inverse(this); + if (typeof options.fn === 'function') { + if (result) { + return options.fn(this); + } else { + return options.inverse(this); + } } + + return result; }); // or 헬퍼 - 하나라도 true인지 확인 (블록 헬퍼) @@ -91,21 +138,32 @@ function registerHandlebarsHelpers() { // 마지막 인자는 Handlebars 옵션 const options = args[args.length - 1]; const values = args.slice(0, -1); + const result = values.some(Boolean); - if (values.some(Boolean)) { - return options.fn(this); - } else { - return options.inverse(this); + if (typeof options.fn === 'function') { + if (result) { + return options.fn(this); + } else { + return options.inverse(this); + } } + + return result; }); // not 헬퍼 - 값 반전 (블록 헬퍼) handlebars.registerHelper('not', function(value: any, options: any) { - if (!value) { - return options.fn(this); - } else { - return options.inverse(this); + const result = !value; + + if (typeof options.fn === 'function') { + if (result) { + return options.fn(this); + } else { + return options.inverse(this); + } } + + return result; }); // formatDate 헬퍼 - 날짜 포맷팅 |
