@@ -14,17 +14,17 @@
15module Main where
15module Main where
17−import qualified Language.PureScript as P
18−import System.Console.CmdTheLine
19import Control.Applicative
17import Control.Applicative
20import Control.Monad
18import Control.Monad
21import Control.Monad.Writer
19import Control.Monad.Writer
22−import System.Exit (exitSuccess, exitFailure)
23−import qualified System.IO.UTF8 as U
24−import qualified Paths_purescript as Paths
25−import Data.Version (showVersion)
27import Data.Function (on)
20import Data.Function (on)
22+import Data.Version (showVersion)
23+import qualified Language.PureScript as P
24+import qualified Paths_purescript as Paths
25+import qualified System.IO.UTF8 as U
26+import System.Console.CmdTheLine
27+import System.Exit (exitSuccess, exitFailure)
29docgen :: FilePath -> IO ()
29docgen :: FilePath -> IO ()
30docgen input = do
30docgen input = do
@@ -61,6 +61,7 @@ renderModules ms = do
61renderModule :: P.Module -> Docs
61renderModule :: P.Module -> Docs
62renderModule (P.Module moduleName ds exps) =
62renderModule (P.Module moduleName ds exps) =
63 let exported = filter (isExported exps) ds
63 let exported = filter (isExported exps) ds
64+ hasTypeclasses = any isTypeClassDeclaration ds
65 headerLevel 2 $ "Module " ++ P.runModuleName moduleName
66 headerLevel 2 $ "Module " ++ P.runModuleName moduleName
@@ -70,8 +71,9 @@ renderModule (P.Module moduleName ds exps) =
71 headerLevel 3 "Type Classes"
72 headerLevel 3 "Type Classes"
74+ when hasTypeclasses $ do
73− renderTypeclassImage
75+ renderTypeclassImage moduleName
75 renderTopLevel exps (filter isTypeClassDeclaration exported)
77 renderTopLevel exps (filter isTypeClassDeclaration exported)
77 headerLevel 3 "Type Class Instances"
79 headerLevel 3 "Type Class Instances"
@@ -85,7 +87,7 @@ renderModule (P.Module moduleName ds exps) =
86isExported :: Maybe [P.DeclarationRef] -> P.Declaration -> Bool
88isExported :: Maybe [P.DeclarationRef] -> P.Declaration -> Bool
87isExported Nothing _ = True
89isExported Nothing _ = True
88−isExported _ (P.TypeInstanceDeclaration _ _ _ _ _) = True
90+isExported _ P.TypeInstanceDeclaration{} = True
89isExported exps (P.PositionedDeclaration _ d) = isExported exps d
91isExported exps (P.PositionedDeclaration _ d) = isExported exps d
90isExported (Just exps) decl = any (matches decl) exps
92isExported (Just exps) decl = any (matches decl) exps
@@ -110,8 +112,10 @@ renderTopLevel exps decls = forM_ (sortBy (compare `on` getName) decls) $ \decl
110 renderDeclaration 4 exps decl
112 renderDeclaration 4 exps decl
113−renderTypeclassImage :: Docs
115+renderTypeclassImage :: P.ModuleName -> Docs
114−renderTypeclassImage = tell [""]
116+renderTypeclassImage name =
117+ let name' = P.runModuleName name
118+ in tell [""]
116renderDeclaration :: Int -> Maybe [P.DeclarationRef] -> P.Declaration -> Docs
120renderDeclaration :: Int -> Maybe [P.DeclarationRef] -> P.Declaration -> Docs
117renderDeclaration n _ (P.TypeDeclaration ident ty) =
121renderDeclaration n _ (P.TypeDeclaration ident ty) =