/- 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 import Std.Data.HashMap import DocGen4.Process import DocGen4.ToHtmlFormat import DocGen4.IncludeStr namespace DocGen4 open Lean Std open scoped DocGen4.Jsx structure SiteContext where root : String result : AnalyzerResult abbrev HtmlM := Reader SiteContext def getRoot : HtmlM String := do (←read).root def getResult : HtmlM AnalyzerResult := do (←read).result def templateExtends {α β : Type} (base : α → HtmlM β) (new : HtmlM α) : HtmlM β := new >>= base def nameToPath (n : Name) : String := do let parts := n.components.map Name.toString return (parts.intersperse "/").foldl (· ++ ·) "" ++ ".html" partial def moduleListAux (h : Hierarchy) : HtmlM Html := do if h.getChildren.toList.length == 0 then
{h.getName.toString}
else let children := Array.mk (h.getChildren.toList.map Prod.snd) -- TODO: Is having no children really the correct criterium for a clickable module? let (dirs, files) := children.partition (λ c => c.getChildren.toList.length != 0) let nodes := (←(dirs.mapM moduleListAux)) ++ (←(files.mapM moduleListAux)) return
{h.getName.toString} [nodes]
def moduleList : HtmlM (Array Html) := do let hierarchy := (←getResult).hierarchy let mut list := Array.empty for (n, cs) in hierarchy.getChildren do list := list.push

{n.toString}

list := list.push $ ←moduleListAux cs list def navbar : HtmlM Html := do def baseHtml (title : String) (site : Html) : HtmlM Html := do {title}

Documentation

{title}

-- TODO: Replace this form with our own search
{site} {←navbar} -- TODO Add the js stuff def index : HtmlM Html := do templateExtends (baseHtml "Index") $

Welcome to the documentation page

What is up?
open IO System def styleCss : String := include_str "./static/style.css" def htmlOutput (result : AnalyzerResult) : IO Unit := do -- TODO: parameterize this let config := { root := "/", result := result } let basePath := FilePath.mk "./build/doc/" let indexHtml := ReaderT.run index config FS.createDirAll basePath FS.writeFile (basePath / "index.html") indexHtml.toString FS.writeFile (basePath / "style.css") styleCss end DocGen4