Refactor and harden graph browser assets
This commit is contained in:
parent
7a940b60c1
commit
f9f7105983
14 changed files with 1955 additions and 1867 deletions
|
|
@ -2,7 +2,6 @@
|
|||
|
||||
from __future__ import annotations
|
||||
|
||||
import ast
|
||||
import os
|
||||
import shutil
|
||||
import subprocess
|
||||
|
|
@ -16,30 +15,11 @@ from docforge.project import Project
|
|||
from docforge.rendering import RenderService
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
SOURCE = ROOT / "src" / "docforge" / "visualization.py"
|
||||
ASSET_ROOT = ROOT / "src" / "docforge" / "assets"
|
||||
|
||||
|
||||
def _graph_browser_html() -> str:
|
||||
tree = ast.parse(SOURCE.read_text(encoding="utf-8"), filename=str(SOURCE))
|
||||
for statement in tree.body:
|
||||
if not isinstance(statement, ast.Assign):
|
||||
continue
|
||||
if any(
|
||||
isinstance(target, ast.Name) and target.id == "_GRAPH_BROWSER_HTML"
|
||||
for target in statement.targets
|
||||
):
|
||||
value = ast.literal_eval(statement.value)
|
||||
if isinstance(value, str):
|
||||
return value
|
||||
raise RuntimeError("Could not find the literal graph-browser HTML asset")
|
||||
|
||||
|
||||
def _embedded(html: str, tag: str) -> str:
|
||||
opening = f"<{tag}>"
|
||||
closing = f"</{tag}>"
|
||||
if html.count(opening) != 1 or html.count(closing) != 1:
|
||||
raise RuntimeError(f"Expected exactly one embedded {tag} asset")
|
||||
return html.split(opening, 1)[1].split(closing, 1)[0]
|
||||
return (ASSET_ROOT / "graph.html").read_text(encoding="utf-8")
|
||||
|
||||
|
||||
def _rendered_manual_html() -> str:
|
||||
|
|
@ -110,7 +90,7 @@ def main() -> int:
|
|||
"--stdin-filename=graph-browser.css",
|
||||
"--max-warnings=0",
|
||||
],
|
||||
_embedded(html, "style"),
|
||||
(ASSET_ROOT / "graph.css").read_text(encoding="utf-8"),
|
||||
),
|
||||
(
|
||||
"JavaScript",
|
||||
|
|
@ -120,7 +100,7 @@ def main() -> int:
|
|||
"--stdin-filename=graph-browser.js",
|
||||
"--max-warnings=0",
|
||||
],
|
||||
_embedded(html, "script"),
|
||||
(ASSET_ROOT / "graph.js").read_text(encoding="utf-8"),
|
||||
),
|
||||
)
|
||||
results = [_run(label, command, content) for label, command, content in checks]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue