-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
106 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
data | ||
data | ||
output |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
packages/email/docsoc-mail-merge/src/sideCardData/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/** | ||
* Handle "sidecar" data - these are JSON files that sit next to rendered template previews, | ||
* containing metadata about the preview, so that we can re-render them later. | ||
* | ||
* @packageDocumentation | ||
*/ | ||
import { TemplatePreview } from "../engines/types"; | ||
import { CSVRecord } from "../util/types"; | ||
|
||
const PARTS_SEPARATOR = "__"; | ||
|
||
export const getRecordPreviewPrefix = (record: CSVRecord, fileNamer: (record: CSVRecord) => string) => | ||
`${fileNamer(record)}`; | ||
|
||
/** Generate predicable prefixes for preview names */ | ||
export const getRecordPreviewPrefixForIndividual = ( | ||
record: CSVRecord, | ||
fileNamer: (record: CSVRecord) => string, | ||
templateEngine: string, | ||
preview: TemplatePreview, | ||
) => [getRecordPreviewPrefix(record, fileNamer), templateEngine, preview.name].join(PARTS_SEPARATOR); | ||
|
||
export const getRecordPreviewPrefixForMetadata = (record: CSVRecord, fileNamer: (record: CSVRecord) => string) => | ||
`${getRecordPreviewPrefix(record, fileNamer)}-metadata.json`; | ||
|
||
// export const writeSidecardData = async () => { |
23 changes: 23 additions & 0 deletions
23
packages/email/docsoc-mail-merge/src/sideCardData/types.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { ENGINES_MAP } from "../engines"; | ||
import { TemplateEngineOptions, TemplatePreview } from "../engines/types"; | ||
import { CSVRecord } from "../util/types"; | ||
|
||
/** | ||
* Outputted to JSON files next to rendered template previews, containing metadata about the preview. | ||
*/ | ||
export interface SidecardData { | ||
/** Record associated with the template rendered */ | ||
record: CSVRecord; | ||
/** Engine used */ | ||
engine: keyof typeof ENGINES_MAP; | ||
/** Options given to the engine */ | ||
engineOptions: TemplateEngineOptions; | ||
/** Data about the files rendered */ | ||
files: Array<{ | ||
filename: string; | ||
/** Data returned from {@link TemplateEngine.renderPreview} */ | ||
engineData: Omit<TemplatePreview, "content"> & { | ||
content: never | undefined; | ||
}; | ||
}>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters