Skip to content
This repository was archived by the owner on Aug 3, 2024. It is now read-only.

Commit f506a35

Browse files
authored
Write meta.json when generating html output (#676)
1 parent a0fe599 commit f506a35

File tree

5 files changed

+30
-2
lines changed

5 files changed

+30
-2
lines changed

CHANGES.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
* to be released
44

5+
* Haddock now writes additional information about the documentation to `meta.json`
6+
57
* Fix renaming of type variables after specializing instance method signatures (#613)
68

79
* Move markup related data types to haddock-library

haddock-api/haddock-api.cabal

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ library
8989
Haddock.Backends.Xhtml.Types
9090
Haddock.Backends.Xhtml.Utils
9191
Haddock.Backends.LaTeX
92+
Haddock.Backends.Meta
9293
Haddock.Backends.HaddockDB
9394
Haddock.Backends.Hoogle
9495
Haddock.Backends.Hyperlinker

haddock-api/src/Haddock.hs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import Data.Version
2929
import Haddock.Backends.Xhtml
3030
import Haddock.Backends.Xhtml.Themes (getThemes)
3131
import Haddock.Backends.LaTeX
32+
import Haddock.Backends.Meta
3233
import Haddock.Backends.Hoogle
3334
import Haddock.Backends.Hyperlinker
3435
import Haddock.Interface
@@ -319,6 +320,7 @@ render dflags flags qual ifaces installedIfaces extSrcMap = do
319320
opt_contents_url opt_index_url unicode qual
320321
pretty
321322
copyHtmlBits odir libDir themes
323+
writeHaddockMeta odir
322324

323325
-- TODO: we throw away Meta for both Hoogle and LaTeX right now,
324326
-- might want to fix that if/when these two get some work on them
@@ -445,9 +447,9 @@ getHaddockLibDir flags =
445447
exists <- doesDirectoryExist p
446448
pure $ if exists then Just p else Nothing
447449

448-
dirs <- mapM check res_dirs
450+
dirs <- mapM check res_dirs
449451
case [p | Just p <- dirs] of
450-
(p : _) -> return p
452+
(p : _) -> return p
451453
_ -> die "Haddock's resource directory does not exist!\n"
452454
#endif
453455
fs -> return (last fs)
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
module Haddock.Backends.Meta where
2+
3+
import Haddock.Utils.Json
4+
import Haddock.Version
5+
6+
import Data.ByteString.Builder (hPutBuilder)
7+
import System.FilePath ((</>))
8+
import System.IO (withFile, IOMode (WriteMode))
9+
10+
-- | Writes a json encoded file containing additional
11+
-- information about the generated documentation. This
12+
-- is useful for external tools (e.g. hackage).
13+
writeHaddockMeta :: FilePath -> IO ()
14+
writeHaddockMeta odir = do
15+
let
16+
meta_json :: Value
17+
meta_json = object [
18+
"haddock_version" .= String projectVersion
19+
]
20+
21+
withFile (odir </> "meta.json") WriteMode $ \h ->
22+
hPutBuilder h (encodeToBuilder meta_json)

haddock.cabal

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ executable haddock
125125
Haddock.Backends.Xhtml.Types
126126
Haddock.Backends.Xhtml.Utils
127127
Haddock.Backends.LaTeX
128+
Haddock.Backends.Meta
128129
Haddock.Backends.HaddockDB
129130
Haddock.Backends.Hoogle
130131
Haddock.Backends.Hyperlinker

0 commit comments

Comments
 (0)