-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun.py
More file actions
47 lines (36 loc) · 1.65 KB
/
Copy pathrun.py
File metadata and controls
47 lines (36 loc) · 1.65 KB
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
39
40
41
42
43
44
45
46
47
"""
07 -- migrate
Upgrading a v1 Inky template to v2 syntax: <columns large="6"> becomes
<column lg="6">, <h-line> becomes <divider>, <spacer size="..."> becomes
<spacer height="...">, class-based button/menu modifiers become
attributes, and <center><menu>...</menu></center> becomes
<menu align="center">. migrate_with_details() returns both the rewritten
HTML and a human-readable list of what changed -- useful as a one-time
upgrade script, or as a report to sanity-check before trusting the
output.
"""
import os
import sys
sys.path.insert(0, os.path.normpath(os.path.join(os.path.dirname(__file__), "..", "..")))
import bootstrap # noqa: E402
import inky # noqa: E402
THIS_DIR = os.path.dirname(os.path.abspath(__file__))
dist = bootstrap.inky_example("07-migrate")
with open(os.path.join(THIS_DIR, "legacy-v1.inky"), encoding="utf-8") as f:
legacy = f.read()
result = inky.migrate_with_details(legacy)
print(f"Changes ({len(result['changes'])}):")
for change in result["changes"]:
print(f" - {change}")
# Write the migrated v2 template to disk -- this is what you'd commit in
# place of the old file after reviewing the change list above.
with open(os.path.join(dist, "migrated.inky"), "w", encoding="utf-8") as f:
f.write(result["html"])
# Prove the migrated template still builds cleanly end to end.
built = inky.build(result["html"], THIS_DIR)
with open(os.path.join(dist, "email.html"), "w", encoding="utf-8") as f:
f.write(built.html)
for warning in built.warnings:
print(f"warning: {warning}", file=sys.stderr)
print(f"\nmigrated.inky: {len(result['html'].encode('utf-8'))} bytes")
print(f"email.html: {len(built.html.encode('utf-8'))} bytes")