2021-12-12 12:21:53 +00:00
|
|
|
/-
|
|
|
|
Copyright (c) 2021 Henrik Böving. All rights reserved.
|
|
|
|
Released under Apache 2.0 license as described in the file LICENSE.
|
|
|
|
Authors: Henrik Böving
|
|
|
|
-/
|
|
|
|
import Lean
|
2022-03-06 17:51:06 +00:00
|
|
|
import Lake
|
2021-12-12 12:21:53 +00:00
|
|
|
import DocGen4.Process
|
2021-12-15 08:24:49 +00:00
|
|
|
import DocGen4.Output.Base
|
|
|
|
import DocGen4.Output.Index
|
|
|
|
import DocGen4.Output.Module
|
|
|
|
import DocGen4.Output.NotFound
|
2022-02-13 14:42:15 +00:00
|
|
|
import DocGen4.Output.Find
|
2022-05-19 18:48:26 +00:00
|
|
|
import DocGen4.Output.SourceLinker
|
2022-07-22 12:48:36 +00:00
|
|
|
import DocGen4.Output.ToJson
|
2022-07-26 10:52:41 +00:00
|
|
|
import DocGen4.LeanInk.Process
|
2022-07-20 23:40:04 +00:00
|
|
|
import Std.Data.HashMap
|
2021-12-12 12:21:53 +00:00
|
|
|
|
|
|
|
namespace DocGen4
|
|
|
|
|
2022-07-20 23:40:04 +00:00
|
|
|
open Lean IO System Output Process Std
|
2021-12-13 12:00:53 +00:00
|
|
|
|
2022-07-20 23:40:04 +00:00
|
|
|
def htmlOutputSetup (config : SiteBaseContext) : IO Unit := do
|
2022-07-21 00:21:07 +00:00
|
|
|
let findBasePath := basePath / "find"
|
2022-06-19 22:31:09 +00:00
|
|
|
|
2022-07-20 23:40:04 +00:00
|
|
|
-- Base structure
|
2022-02-13 14:42:15 +00:00
|
|
|
FS.createDirAll basePath
|
2022-07-21 19:05:19 +00:00
|
|
|
FS.createDirAll findBasePath
|
2022-06-19 22:31:09 +00:00
|
|
|
FS.createDirAll srcBasePath
|
2022-07-21 19:05:19 +00:00
|
|
|
FS.createDirAll declarationsBasePath
|
2022-02-13 14:42:15 +00:00
|
|
|
|
2022-07-21 00:21:07 +00:00
|
|
|
-- All the doc-gen static stuff
|
|
|
|
let indexHtml := ReaderT.run index config |>.toString
|
|
|
|
let notFoundHtml := ReaderT.run notFound config |>.toString
|
2022-07-21 20:06:26 +00:00
|
|
|
let navbarHtml := ReaderT.run navbar config |>.toString
|
2022-07-21 00:21:07 +00:00
|
|
|
let docGenStatic := #[
|
|
|
|
("style.css", styleCss),
|
|
|
|
("declaration-data.js", declarationDataCenterJs),
|
|
|
|
("nav.js", navJs),
|
|
|
|
("how-about.js", howAboutJs),
|
|
|
|
("search.js", searchJs),
|
|
|
|
("mathjax-config.js", mathjaxConfigJs),
|
2022-07-22 12:48:36 +00:00
|
|
|
("instances.js", instancesJs),
|
2022-07-22 14:15:37 +00:00
|
|
|
("importedBy.js", importedByJs),
|
2022-07-21 00:21:07 +00:00
|
|
|
("index.html", indexHtml),
|
2022-07-21 20:06:26 +00:00
|
|
|
("404.html", notFoundHtml),
|
|
|
|
("navbar.html", navbarHtml)
|
2022-07-21 00:21:07 +00:00
|
|
|
]
|
|
|
|
for (fileName, content) in docGenStatic do
|
|
|
|
FS.writeFile (basePath / fileName) content
|
2022-07-20 23:40:04 +00:00
|
|
|
|
2022-07-21 00:21:07 +00:00
|
|
|
let findHtml := ReaderT.run find { config with depthToRoot := 1 } |>.toString
|
|
|
|
let findStatic := #[
|
|
|
|
("index.html", findHtml),
|
|
|
|
("find.js", findJs)
|
|
|
|
]
|
|
|
|
for (fileName, content) in findStatic do
|
|
|
|
FS.writeFile (findBasePath / fileName) content
|
2022-02-22 04:40:14 +00:00
|
|
|
|
2022-07-21 00:21:07 +00:00
|
|
|
let alectryonStatic := #[
|
|
|
|
("alectryon.css", alectryonCss),
|
|
|
|
("alectryon.js", alectryonJs),
|
|
|
|
("docutils_basic.css", docUtilsCss),
|
|
|
|
("pygments.css", pygmentsCss)
|
|
|
|
]
|
2022-07-20 23:40:04 +00:00
|
|
|
|
2022-07-21 00:21:07 +00:00
|
|
|
for (fileName, content) in alectryonStatic do
|
|
|
|
FS.writeFile (srcBasePath / fileName) content
|
2022-02-20 17:12:49 +00:00
|
|
|
|
2022-07-21 20:43:33 +00:00
|
|
|
def htmlOutputDeclarationDatas (result : AnalyzerResult) : HtmlT IO Unit := do
|
|
|
|
for (_, mod) in result.moduleInfo.toArray do
|
|
|
|
let jsonDecls ← Module.toJson mod
|
2022-07-22 12:48:36 +00:00
|
|
|
FS.writeFile (declarationsBasePath / s!"declaration-data-{mod.name}.bmp") (toJson jsonDecls).compress
|
2022-07-21 20:43:33 +00:00
|
|
|
|
2022-07-26 11:56:22 +00:00
|
|
|
def htmlOutputResults (baseConfig : SiteBaseContext) (result : AnalyzerResult) (ws : Lake.Workspace) (ink : Bool) : IO Unit := do
|
2022-07-20 23:40:04 +00:00
|
|
|
let config : SiteContext := {
|
|
|
|
result := result,
|
2022-07-21 00:25:26 +00:00
|
|
|
sourceLinker := ←sourceLinker ws
|
2022-07-26 11:56:22 +00:00
|
|
|
leanInkEnabled := ink
|
2022-07-20 23:40:04 +00:00
|
|
|
}
|
2022-07-21 17:07:35 +00:00
|
|
|
|
|
|
|
FS.createDirAll basePath
|
2022-07-21 19:05:19 +00:00
|
|
|
FS.createDirAll declarationsBasePath
|
2022-07-21 17:07:35 +00:00
|
|
|
|
2022-07-20 23:40:04 +00:00
|
|
|
-- Rendering the entire lean compiler takes time....
|
|
|
|
--let sourceSearchPath := ((←Lean.findSysroot) / "src" / "lean") :: ws.root.srcDir :: ws.leanSrcPath
|
|
|
|
let sourceSearchPath := ws.root.srcDir :: ws.leanSrcPath
|
|
|
|
|
2022-07-23 11:01:25 +00:00
|
|
|
discard <| htmlOutputDeclarationDatas result |>.run config baseConfig
|
2022-07-20 23:40:04 +00:00
|
|
|
|
2022-06-20 16:39:55 +00:00
|
|
|
for (modName, module) in result.moduleInfo.toArray do
|
|
|
|
let fileDir := moduleNameToDirectory basePath modName
|
|
|
|
let filePath := moduleNameToFile basePath modName
|
2022-02-15 11:12:17 +00:00
|
|
|
-- path: 'basePath/module/components/till/last.html'
|
|
|
|
-- The last component is the file name, so we drop it from the depth to root.
|
2022-07-26 10:52:41 +00:00
|
|
|
let baseConfig := { baseConfig with
|
|
|
|
depthToRoot := modName.components.dropLast.length
|
|
|
|
currentName := some modName
|
|
|
|
}
|
2022-07-20 23:40:04 +00:00
|
|
|
let moduleHtml := moduleToHtml module |>.run config baseConfig
|
2022-07-23 11:01:25 +00:00
|
|
|
FS.createDirAll fileDir
|
2022-02-15 11:12:17 +00:00
|
|
|
FS.writeFile filePath moduleHtml.toString
|
2022-07-26 11:56:22 +00:00
|
|
|
if ink then
|
2022-06-20 16:39:55 +00:00
|
|
|
if let some inputPath ← Lean.SearchPath.findModuleWithExt sourceSearchPath "lean" module.name then
|
|
|
|
IO.println s!"Inking: {modName.toString}"
|
|
|
|
-- path: 'basePath/src/module/components/till/last.html'
|
|
|
|
-- The last component is the file name, however we are in src/ here so dont drop it this time
|
2022-07-26 10:52:41 +00:00
|
|
|
let baseConfig := {baseConfig with depthToRoot := modName.components.length }
|
|
|
|
Process.LeanInk.runInk inputPath |>.run config baseConfig
|
2021-12-12 12:21:53 +00:00
|
|
|
|
2022-07-20 23:40:04 +00:00
|
|
|
def getSimpleBaseContext (hierarchy : Hierarchy) : SiteBaseContext :=
|
|
|
|
{
|
|
|
|
depthToRoot := 0,
|
|
|
|
currentName := none,
|
|
|
|
hierarchy
|
|
|
|
}
|
|
|
|
|
2022-07-21 19:12:15 +00:00
|
|
|
def htmlOutputIndex (baseConfig : SiteBaseContext) : IO Unit := do
|
2022-07-21 17:07:35 +00:00
|
|
|
htmlOutputSetup baseConfig
|
|
|
|
|
2022-07-23 18:40:08 +00:00
|
|
|
let mut index : JsonIndex := { }
|
2022-07-21 19:05:19 +00:00
|
|
|
for entry in ←System.FilePath.readDir declarationsBasePath do
|
2022-07-21 16:26:01 +00:00
|
|
|
if entry.fileName.startsWith "declaration-data-" && entry.fileName.endsWith ".bmp" then
|
2022-07-22 12:48:36 +00:00
|
|
|
let fileContent ← FS.readFile entry.path
|
|
|
|
let .ok jsonContent := Json.parse fileContent | unreachable!
|
|
|
|
let .ok (module : JsonModule) := fromJson? jsonContent | unreachable!
|
2022-07-23 18:40:08 +00:00
|
|
|
index := index.addModule module |>.run baseConfig
|
|
|
|
|
|
|
|
let finalJson := toJson index
|
2022-07-21 16:26:01 +00:00
|
|
|
-- The root JSON for find
|
2022-07-22 12:48:36 +00:00
|
|
|
FS.writeFile (declarationsBasePath / "declaration-data.bmp") finalJson.compress
|
2022-07-21 16:26:01 +00:00
|
|
|
|
2022-07-20 23:40:04 +00:00
|
|
|
/--
|
|
|
|
The main entrypoint for outputting the documentation HTML based on an
|
|
|
|
`AnalyzerResult`.
|
|
|
|
-/
|
2022-07-26 11:56:22 +00:00
|
|
|
def htmlOutput (result : AnalyzerResult) (hierarchy : Hierarchy) (ws : Lake.Workspace) (ink : Bool) : IO Unit := do
|
2022-07-20 23:40:04 +00:00
|
|
|
let baseConfig := getSimpleBaseContext hierarchy
|
2022-07-26 11:56:22 +00:00
|
|
|
htmlOutputResults baseConfig result ws ink
|
2022-07-21 19:12:15 +00:00
|
|
|
htmlOutputIndex baseConfig
|
2022-07-20 23:40:04 +00:00
|
|
|
|
2021-12-12 12:21:53 +00:00
|
|
|
end DocGen4
|
|
|
|
|