-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.py
More file actions
38 lines (32 loc) · 997 Bytes
/
build.py
File metadata and controls
38 lines (32 loc) · 997 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import json
import os
import inky
# Read the source template
with open("src/emails/welcome.inky") as f:
template = f.read()
os.makedirs("dist", exist_ok=True)
# Build without data merge (template tags pass through)
html = inky.transform_inline(template)
with open("dist/welcome.html", "w") as f:
f.write(html)
print("built dist/welcome.html")
# Build with data merge
with open("data/welcome.json") as f:
data = f.read()
merged = inky.transform_with_data(template, data)
with open("dist/welcome-merged.html", "w") as f:
f.write(merged)
print("built dist/welcome-merged.html")
# Generate plain text
text = inky.to_plain_text(merged)
with open("dist/welcome.txt", "w") as f:
f.write(text)
print("built dist/welcome.txt")
# Validate
diagnostics = json.loads(inky.validate(template))
if diagnostics:
print("\nvalidation warnings:")
for d in diagnostics:
print(f" [{d['severity']}] {d['rule']}: {d['message']}")
else:
print("\nno validation issues found")