From 0adf66f90ad0307d9db403a4f51b784ae4ffe07b Mon Sep 17 00:00:00 2001 From: Ahn Kiwook Date: Sat, 22 Jul 2017 15:31:16 +0900 Subject: [PATCH 1/2] Add documents for HTML target --- src/Nirum/Targets/Docs.hs | 77 +++++++++++++++++++++++++++------------ 1 file changed, 53 insertions(+), 24 deletions(-) diff --git a/src/Nirum/Targets/Docs.hs b/src/Nirum/Targets/Docs.hs index 0fa55c5..be3d4ec 100644 --- a/src/Nirum/Targets/Docs.hs +++ b/src/Nirum/Targets/Docs.hs @@ -15,6 +15,7 @@ import Text.Blaze.Html.Renderer.Utf8 (renderHtml) import Text.Hamlet (Html, shamlet) import Nirum.Constructs (Construct (toCode)) +import Nirum.Constructs.Declaration (Documented (docsBlock)) import qualified Nirum.Constructs.Declaration as DE import qualified Nirum.Constructs.DeclarationSet as DES import qualified Nirum.Constructs.Docs as D @@ -31,7 +32,7 @@ import qualified Nirum.Constructs.TypeExpression as TE import Nirum.Docs ( Block (Heading) , filterReferences ) -import Nirum.Docs.Html (renderInlines) +import Nirum.Docs.Html (render, renderInlines) import Nirum.Package ( BoundModule (boundPackage, modulePath) , Package (Package, metadata, modules) , resolveBoundModule @@ -128,60 +129,88 @@ module' docsModule = layout pkg path $ [shamlet| typeDecl :: BoundModule Docs -> Identifier -> TD.TypeDeclaration -> Html typeDecl mod' ident - TD.TypeDeclaration { TD.type' = TD.Alias cname } = [shamlet| + tc@TD.TypeDeclaration { TD.type' = TD.Alias cname } = [shamlet|

type #{toNormalizedText ident} + $maybe d <- docsBlock tc +

#{preEscapedToMarkup $ render d}

= #{typeExpression mod' cname} |] typeDecl mod' ident - TD.TypeDeclaration { TD.type' = TD.UnboxedType innerType } = [shamlet| -

unboxed #{toNormalizedText ident} -

(#{typeExpression mod' innerType}) -|] + tc@TD.TypeDeclaration { TD.type' = TD.UnboxedType innerType } = + [shamlet| +

unboxed #{toNormalizedText ident} + $maybe d <- docsBlock tc +

#{preEscapedToMarkup $ render d} +

(#{typeExpression mod' innerType}) + |] typeDecl _ ident - TD.TypeDeclaration { TD.type' = TD.EnumType members } = [shamlet| + tc@TD.TypeDeclaration { TD.type' = TD.EnumType members } = [shamlet|

enum #{toNormalizedText ident} -