jspahrsummers/documentalist — pull request #39 by maxpow4h (2013-08-30 08:47:05+00:00)
Title: Package traversal

Packages aren't really Traversable or Foldable. When we do either of those operations, the result should be dependent on the other fields of the data.

Now a single `traversePackage` higher order function is exposed.

It also carries the depth of nested declarations.

This lets you write `Writers` like (Using the `Control.Monad.Writer.Strict` Writer):

```hs
writeMarkdown p = putStrLn $ intercalate "\n" $ execWriter $ (packageTraverse pkgName modName decl p :: Writer [String] ())

pkgName s = tell ["# " ++ s]
modName s = tell ["## " ++ s]

decl depth (DecLeaf doc (Identifier i) y) = do
tell [replicate (3 + depth) '#' ++ " " ++ i]
showDocBlock doc
decl depth (DecNode doc (Identifier i) y _) = do
tell [replicate (3 + depth) '#' ++ " " ++ i]
showDocBlock doc
decl depth x = return ()

showDocBlock (Just doc) = do
let desc = description doc
params = parameters doc
ex = example doc
res = result doc
tell ["**Summary:** " ++ show (summary doc)]
when (null desc) $ tell ["**Description:** " ++ show desc]
when (null params) $ tell ["**Parameters:** " ++ show params]
when (isJust ex) $ tell ["**Example:** " ++ show (fromJust ex)]
when (isJust res) $ tell ["**Result:** " ++ show (fromJust res)]
tell [""]

showDocBlock Nothing = return ()
```