Skip to content

Commit 182e9cb

Browse files
committed
refactor: report use the local css/js
Add a static file renderer to go alongside the jinja2 renderer for the static dependencies that do no need templating. This essentially creates a copy of the files in the output directory. Now we have the css/js dependencies locally generated we can update the report template to use them. Signed-off-by: James McCorrie <[email protected]>
1 parent dc18f96 commit 182e9cb

File tree

4 files changed

+32
-11
lines changed

4 files changed

+32
-11
lines changed

src/dvsim/report/generate.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
from dvsim.logging import log
1010
from dvsim.report.data import FlowResults, ResultsSummary
11-
from dvsim.templates.render import render_template
11+
from dvsim.templates.render import render_static, render_template
1212

1313
__all__ = (
1414
"gen_block_report",
@@ -63,7 +63,16 @@ def gen_summary_report(summary: ResultsSummary, path: Path) -> None:
6363
(path / "index.json").write_text(summary.model_dump_json())
6464

6565
# Generate style CSS
66-
(path / "style.css").write_text(render_template(path="reports/style.css"))
66+
for name in (
67+
"css/style.css",
68+
"css/bootstrap.min.css",
69+
"js/bootstrap.bundle.min.js",
70+
"js/htmx.min.js",
71+
):
72+
output = path / name
73+
74+
output.parent.mkdir(parents=True, exist_ok=True)
75+
output.write_text(render_static(path=name))
6776

6877
# HTMX wrapper
6978
(path / "index.html").write_text(render_template(path="reports/wrapper.html"))

src/dvsim/templates/render.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"""
1010

1111
from collections.abc import Mapping
12+
from importlib import resources
1213

1314
from jinja2 import Environment, PackageLoader, select_autoescape
1415

@@ -17,6 +18,22 @@
1718
_env: Environment | None = None
1819

1920

21+
def render_static(path: str) -> str:
22+
"""Render static files packaged with DVSim.
23+
24+
Args:
25+
path: relative path to the DVSim template directory
26+
27+
Returns:
28+
string containing the static file content
29+
30+
"""
31+
return resources.read_text(
32+
"dvsim",
33+
f"templates/static/{path}",
34+
)
35+
36+
2037
def render_template(path: str, data: Mapping[str, object] | None = None) -> str:
2138
"""Render a template packaged with DVSim.
2239

src/dvsim/templates/reports/wrapper.html

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,9 @@
1010
<meta charset="utf-8">
1111
<meta name="viewport" content="width=device-width, initial-scale=1">
1212
<title>Simulation Results</title>
13-
<script src="https://unpkg.com/[email protected]"></script>
14-
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css"
15-
rel="stylesheet"
16-
integrity="sha384-QWTKZyjpPEjISv5WaRU9OFeRpok6YctnYmDr5pNlyT2bRjXh0JMhjY6hW+ALEwIH"
17-
crossorigin="anonymous">
18-
<link href="style.css" rel="stylesheet">
13+
<script src="js/htmx.min.js"></script>
14+
<link href="css/bootstrap.min.css" rel="stylesheet">
15+
<link href="css/style.css" rel="stylesheet">
1916
</head>
2017
<body>
2118

@@ -35,8 +32,6 @@
3532
hx-trigger="load"
3633
hx-target="#report-content"></div>
3734

38-
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"
39-
integrity="sha384-YvpcrYf0tY3lHB60NNkmXc5s9fDVZLESaAA55NDzOxhy9GkcIdslK1eN7N6jIeHz"
40-
crossorigin="anonymous"></script>
35+
<script src="js/bootstrap.bundle.min.js"></script>
4136
</body>
4237
</html>

0 commit comments

Comments
 (0)