Verified Commit 5ca29d3b authored by Camil Staps's avatar Camil Staps 🚀

Add all documentation to functions, generics and macros (#5)

parent e0e3544c
Pipeline #15076 passed with stage
in 1 minute and 8 seconds
......@@ -9,6 +9,7 @@ import StdString
import StdTuple
import Clean.Doc => qualified :: ParamDoc{name}
import Clean.Types.Util
import Control.Applicative
import Control.Monad
import Data.Error
......@@ -22,6 +23,7 @@ import System.FilePath
import Text => qualified join
import Text.GenJSON
import Text.HTML
import Text.Language
import Clean.Doc.ModuleCollection
import Clean.Doc.ModuleCollection.Index => qualified :: IndexItem{name}
......@@ -95,9 +97,9 @@ where
, DivTag [ClassAttr "clean-doc"] <$> pure <$> Text <$> (docDescription =<< m.doc)
, Just $ DivTag [IdAttr "type_defs"] typedefs
, Just $ DivTag [IdAttr "classes"] classes
, Just $ DivTag [IdAttr "generics"] generics
, Just $ DivTag [IdAttr "functions"] functions
, Just $ DivTag [IdAttr "macros"] macros
, Just $ DivTag [IdAttr "generics"] $ functions "generic" "gen" m.elem.mod_generics
, Just $ DivTag [IdAttr "functions"] $ functions "function" "fun" m.elem.mod_functions
, Just $ DivTag [IdAttr "macros"] $ functions "macro" "macro" m.elem.mod_macros
]
typedefs = if (isEmpty m.elem.mod_type_defs) []
......@@ -120,35 +122,31 @@ where
, Just $ PreTag [ClassAttr "clean-code"] [Text (fromJust dc.repr)]
]
generics = if (isEmpty m.elem.mod_generics) []
[ H1Tag [] [Text "Generics"]
: map html (sort m.elem.mod_generics)
functions _ _ [] = []
functions kind slug xs =
[ H1Tag [] [Text $ {toUpper kind.[0]} +++ kind % (1,size kind-1) +++ "s"]
: map html (sort xs)
]
where
html dg = collapsable thisfp "generic" ("gen-" +++ dg.name) dg.name dg.pos $ catMaybes
[ DivTag [ClassAttr "clean-doc"] <$> pure <$> Text <$> (docDescription =<< dg.doc)
, Just $ PreTag [ClassAttr "clean-code"] [Text (fromJust dg.repr)]
]
functions = if (isEmpty m.elem.mod_functions) []
[ H1Tag [] [Text "Functions"]
: map html (sort m.elem.mod_functions)
]
where
html df = collapsable thisfp "function" ("fun-" +++ df.name) df.name df.pos $ catMaybes
html df = collapsable thisfp kind (slug +++ "-" +++ df.name) df.name df.pos $ catMaybes
[ DivTag [ClassAttr "clean-doc"] <$> pure <$> Text <$> (docDescription =<< df.doc)
, Just $ PreTag [ClassAttr "clean-code"] [Text (fromJust df.repr)]
, PTag [ClassAttr "clean-doc"] <$> pure <$> Text <$> (docComplexity =<< df.doc)
, itemDocumentation "Type variable" =<< docVars <$> df.doc
, itemDocumentation "Parameter" =<< docParams <$> df.doc
, itemDocumentation "Result" =<< docResults <$> df.doc
, itemDocumentation "May throw exception" =<< docThrows <$> df.doc
, Just $ PreTag [ClassAttr "clean-code"] [Text $ case docType =<< df.doc of
Nothing -> fromJust df.repr
Just t -> df.name +++ " :: " +++ t <+ "\n" +++ fromJust df.repr]
]
macros = if (isEmpty m.elem.mod_macros) []
[ H1Tag [] [Text "Macros"]
: map html (sort m.elem.mod_macros)
itemDocumentation :: !String ![a] -> Maybe HtmlTag | toString a
itemDocumentation name [] = Nothing
itemDocumentation name [x] = Just $ PTag [ClassAttr "clean-doc"] [Text $ name +++ ": " <+ x]
itemDocumentation name xs = Just $ DivTag []
[ PTag [] [Text $ pluralise English name]
, UlTag [] [LiTag [ClassAttr "clean-doc"] [Text $ toString x] \\ x <- xs]
]
where
html dm = collapsable thisfp "macro" ("macro-" +++ dm.name) dm.name dm.pos $ catMaybes
[ DivTag [ClassAttr "clean-doc"] <$> pure <$> Text <$> (docDescription =<< dm.doc)
, Just $ PreTag [ClassAttr "clean-code"] [Text (fromJust dm.repr)]
]
collapsable :: !FilePath !String !String !String !ElementPosition !a -> HtmlTag | html a
collapsable thisfp icon id title pos body = DivTag
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment