chore: use attribute spreads

main
Gabriel Ebner 2022-01-20 14:51:24 +01:00
parent e350c16417
commit 69b5ee76d3
3 changed files with 13 additions and 23 deletions

View File

@ -10,8 +10,8 @@ def ctorToHtml (i : NameInfo) : HtmlM Html := do
let name := i.name.toString let name := i.name.toString
return <li «class»="constructor" id={name}>{shortName} : [←infoFormatToHtml i.type]</li> return <li «class»="constructor" id={name}>{shortName} : [←infoFormatToHtml i.type]</li>
def inductiveToHtml (i : InductiveInfo) : HtmlM (Array Html) := do def inductiveToHtml (i : InductiveInfo) : HtmlM (Array Html) :=
#[Html.element "ul" false #[("class", "constructors")] (←i.ctors.toArray.mapM ctorToHtml)] return #[<ul "class"="constructors">[← i.ctors.toArray.mapM ctorToHtml]</ul>]
end Output end Output
end DocGen4 end DocGen4

View File

@ -13,16 +13,10 @@ namespace Output
open Lean open Lean
open scoped DocGen4.Jsx open scoped DocGen4.Jsx
def moduleListFile (file : Name) : HtmlM Html := do def moduleListFile (file : Name) : HtmlM Html :=
let attributes := match ←getCurrentName with return <div "class"="nav_link" [if (← getCurrentName) == file then #[("visible", "")] else #[]]>
| some name => <a href={← moduleNameToLink file}>{file.toString}</a>
if file == name then </div>
#[("class", "nav_link"), ("visible", "")]
else
#[("class", "nav_link")]
| none => #[("class", "nav_link")]
let nodes := #[<a href={s!"{←moduleNameToLink file}"}>{file.toString}</a>]
return Html.element "div" false attributes nodes
partial def moduleListDir (h : Hierarchy) : HtmlM Html := do partial def moduleListDir (h : Hierarchy) : HtmlM Html := do
let children := Array.mk (h.getChildren.toList.map Prod.snd) let children := Array.mk (h.getChildren.toList.map Prod.snd)
@ -31,16 +25,12 @@ partial def moduleListDir (h : Hierarchy) : HtmlM Html := do
let dirNodes ← (dirs.mapM moduleListDir) let dirNodes ← (dirs.mapM moduleListDir)
let fileNodes ← (files.mapM moduleListFile) let fileNodes ← (files.mapM moduleListFile)
let moduleLink ← moduleNameToLink h.getName let moduleLink ← moduleNameToLink h.getName
let attributes := match ←getCurrentName with return <details "class"="nav_sect" "data-path"={moduleLink}
| some name => [if (← getCurrentName).any (h.getName.isPrefixOf ·) then #[("open", "")] else #[]]>
if h.getName.isPrefixOf name then <summary>{h.getName.toString}</summary>
#[("class", "nav_sect"), ("data-path", moduleLink), ("open", "")] [dirNodes]
else [fileNodes]
#[("class", "nav_sect"), ("data-path", moduleLink)] </details>
| none =>
#[("class", "nav_sect"), ("data-path", moduleLink)]
let nodes := #[<summary>{h.getName.toString}</summary>] ++ dirNodes ++ fileNodes
return Html.element "details" false attributes nodes
def moduleList : HtmlM (Array Html) := do def moduleList : HtmlM (Array Html) := do
let hierarchy := (←getResult).hierarchy let hierarchy := (←getResult).hierarchy

View File

@ -93,7 +93,7 @@ def translateAttrs (attrs : Array Syntax) : MacroM Syntax := do
| `(jsxAttrVal| {$v}) => v | `(jsxAttrVal| {$v}) => v
| `(jsxAttrVal| $v:strLit) => v | `(jsxAttrVal| $v:strLit) => v
| _ => Macro.throwUnsupported | _ => Macro.throwUnsupported
`(($as).push ($n, $v)) `(($as).push ($n, ($v : String)))
| `(jsxAttr| [$t]) => `($as ++ ($t : Array (String × String))) | `(jsxAttr| [$t]) => `($as ++ ($t : Array (String × String)))
| _ => Macro.throwUnsupported | _ => Macro.throwUnsupported
return as return as