Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
joneugster committed Sep 2, 2024
1 parent 0a6ed6c commit 862902e
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions ImportGraph/Cli.lean
Original file line number Diff line number Diff line change
Expand Up @@ -140,23 +140,24 @@ def importGraphCLI (args : Cli.Parsed) : IO UInt32 := do
| "dot" => writeFile fp (outFiles.find! "dot")
| "gexf" => IO.FS.writeFile fp (outFiles.find! "gexf")
| "html" =>
let gexfFile := (outFiles.find! "gexf")
-- use `html-template/index.html` and insert any dependencies to make it
-- a stand-alone HTML file.
let gexFile := (outFiles.find! "gexf")
-- The directory where the import-graph soure is located
-- note: changes in `index.html` might need to be reflected here!
let exeDir := (FilePath.parent (← IO.appPath) |>.get!) / ".." / ".." / ".."
let mut html ← IO.FS.readFile <| ← IO.FS.realPath ( exeDir / "html-template" / "index.html")
for dep in (#[
"vendor" / "sigma.min.js",
"vendor" / "graphology.min.js",
"vendor" / "graphology-library.min.js" ] : Array FilePath) do
let depContent ← IO.FS.readFile <| ← IO.FS.realPath (exeDir / "html-template" / dep)
html := html.replace s!"<script src=\"{dep}\"></script>"
s!"<script>{depContent}</script>"
html := html.replace "fetch(\"imports.gexf\").then((res) => res.text()).then(render_gexf)"
s!"render_gexf(\"{gexFile.replace "\n" ""|>.replace "\"" "\\\""}\")"
|>.replace "<h1>Import Graph</h1>"
s!"<h1>Import Graph for {to}</h1>"
html := html.replace s!"<script src=\"{dep}\"></script>" s!"<script>{depContent}</script>"
-- inline the graph data
-- note: changes in `index.html` might need to be reflected here!
let escapedFile := gexfFile.replace "\n" "" |>.replace "\"" "\\\""
html := html
|>.replace "fetch(\"imports.gexf\").then((res) => res.text()).then(render_gexf)" s!"render_gexf(\"{escapedFile}\")"
|>.replace "<h1>Import Graph</h1>" s!"<h1>Import Graph for {to}</h1>"
IO.FS.writeFile fp html
| some ext => try
_ ← runCmdWithInput "dot" #["-T" ++ ext, "-o", o] (outFiles.find! "dot")
Expand Down

0 comments on commit 862902e

Please sign in to comment.