templates.ts 627 B

1234567891011121314
  1. export function ensureDefine(templateName: string, templateContent: string): string {
  2. // notification template content must be wrapped in {{ define "name" }} tag,
  3. // but this is not obvious because user also has to provide name separately in the form.
  4. // so if user does not manually add {{ define }} tag, we do it automatically
  5. let content = templateContent.trim();
  6. if (!content.match(/\{\{\s*define/)) {
  7. const indentedContent = content
  8. .split('\n')
  9. .map((line) => ' ' + line)
  10. .join('\n');
  11. content = `{{ define "${templateName}" }}\n${indentedContent}\n{{ end }}`;
  12. }
  13. return content;
  14. }