@@ -26,15 +26,15 @@ import qualified System.IO.UTF8 as U
2626import System.Console.CmdTheLine
2727import System.Exit (exitSuccess, exitFailure)
2828
29−docgen :: FilePath -> IO ()
30−docgen input = do
29+docgen :: FilePath -> Bool -> IO ()
30+docgen input showHierarchy = do
3131 text <- U.readFile input
3232 case P.runIndentParser input P.parseModules text of
3333 Left err -> do
3434 U.print err
3535 exitFailure
3636 Right ms -> do
37− U.putStrLn . runDocs $ renderModules ms
37+ U.putStrLn . runDocs $ (renderModules showHierarchy) ms
3838 exitSuccess
3939
4040type Docs = Writer [String] ()
@@ -53,13 +53,14 @@ atIndent indent text =
5353 let ls = lines text in
5454 forM_ ls $ \l -> tell [replicate indent ' ' ++ l]
5555
56−renderModules :: [P.Module] -> Docs
57−renderModules ms = do
56+renderModules :: Bool -> [P.Module] -> Docs
57+renderModules showHierarchy ms = do
5858 headerLevel 1 "Module Documentation"
59− mapM_ renderModule ms
59+ spacer
60+ mapM_ (renderModule showHierarchy) ms
6061
61−renderModule :: P.Module -> Docs
62−renderModule (P.Module moduleName ds exps) =
62+renderModule :: Bool -> P.Module -> Docs
63+renderModule showHierarchy (P.Module moduleName ds exps) =
6364 let exported = filter (isExported exps) ds
6465 hasTypes = any isTypeDeclaration ds
6566 hasTypeclasses = any isTypeClassDeclaration ds
@@ -76,8 +77,9 @@ renderModule (P.Module moduleName ds exps) =
7677 when hasTypeclasses $ do
7778 headerLevel 3 "Type Classes"
7879 spacer
79− renderTypeclassImage moduleName
80− spacer
80+ when showHierarchy $ do
81+ renderTypeclassImage moduleName
82+ spacer
8183 renderTopLevel exps (filter isTypeClassDeclaration exported)
8284 spacer
8385 when hasTypeclassInstances $ do
@@ -191,8 +193,11 @@ isTypeInstanceDeclaration _ = False
191193inputFile :: Term FilePath
192194inputFile = value $ pos 0 "input.ps" $ posInfo { posDoc = "The input .ps file" }
193195
196+includeHeirarcy :: Term Bool
197+includeHeirarcy = value $ flag $ (optInfo [ "h", "hierarchy-images" ]) { optDoc = "Include markdown for type class hierarchy images in the output." }
198+
194199term :: Term (IO ())
195−term = docgen <$> inputFile
200+term = docgen <$> inputFile <*> includeHeirarcy
196201
197202termInfo :: TermInfo
198203termInfo = defTI