Skip to content

Commit

Permalink
Add type list for each module
Browse files Browse the repository at this point in the history
  • Loading branch information
AiOO authored and dahlia committed Mar 11, 2017
1 parent 94abfc1 commit 19ccbf2
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion src/Nirum/Targets/Docs.hs
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,25 @@ import Text.Blaze.Html.Renderer.Utf8 (renderHtml)
import Text.Hamlet (Html, shamlet)

import Nirum.Constructs (Construct (toCode))
import qualified Nirum.Constructs.Declaration as DE
import qualified Nirum.Constructs.DeclarationSet as DES
import qualified Nirum.Constructs.Docs as D
import Nirum.Constructs.Identifier (toNormalizedString)
import Nirum.Constructs.Identifier ( Identifier
, toNormalizedString
, toNormalizedText
)
import Nirum.Constructs.Module (Module (Module, docs))
import Nirum.Constructs.ModulePath (ModulePath)
import Nirum.Constructs.Name (Name (facialName))
import qualified Nirum.Constructs.TypeDeclaration as TD
import Nirum.Docs ( Block (Heading)
, filterReferences
)
import Nirum.Docs.Html (renderInlines)
import Nirum.Package ( BoundModule (boundPackage, modulePath)
, Package (Package, metadata, modules)
, resolveBoundModule
, types
)
import Nirum.Package.Metadata ( Author (Author, email, name, uri)
, Metadata (authors)
Expand Down Expand Up @@ -68,12 +76,31 @@ $doctype 5
<body>
<h1>
<code>#{path}
$forall (ident, decl) <- types'
<h2>#{showKind decl} <code>#{toNormalizedText ident}</code>
|]
where
md :: Metadata Docs
md = metadata $ boundPackage docsModule
path :: T.Text
path = toCode $ modulePath docsModule
showKind :: TD.TypeDeclaration -> T.Text
showKind TD.ServiceDeclaration {} = "service"
showKind TD.TypeDeclaration { TD.type' = type'' } = case type'' of
TD.Alias {} -> "alias"
TD.UnboxedType {} -> "unboxed"
TD.EnumType {} -> "enum"
TD.RecordType {} -> "record"
TD.UnionType {} -> "union"
TD.PrimitiveType {} -> "primitive"
showKind TD.Import {} = "import"
types' :: [(Identifier, TD.TypeDeclaration)]
types' = [ (facialName $ DE.name decl, decl)
| decl <- DES.toList $ types docsModule
, case decl of
TD.Import {} -> False
_ -> True
]

contents :: Package Docs -> Html
contents Package { metadata = md, modules = ms } = [shamlet|
Expand Down

0 comments on commit 19ccbf2

Please sign in to comment.