hs-bindgen-1.0.0.0: test/hs-bindgen/Test/HsBindgen/Fixtures/Haddock.hs
-- | Haddock index page generation for fixture documentation
--
module Test.HsBindgen.Fixtures.Haddock (
generateHaddockIndex
) where
import System.Directory (createDirectoryIfMissing)
import System.FilePath ((</>))
import Test.HsBindgen.Fixtures.Utils (sanitizeLibName)
{-------------------------------------------------------------------------------
Index page generation
-------------------------------------------------------------------------------}
-- | Generate an HTML index page for browsing fixture haddock documentation
generateHaddockIndex ::
String -- ^ Library name prefix (e.g. @\"fixture-\"@)
-> FilePath -- ^ Haddock output directory
-> [String] -- ^ Compiled fixture names
-> Int -- ^ Number of skipped fixtures
-> IO ()
generateHaddockIndex prefix haddockDir compiled skippedCount = do
createDirectoryIfMissing True haddockDir
writeFile (haddockDir </> "index.html") $ unlines $
[ "<!DOCTYPE html>"
, "<html><head>"
, "<meta charset=\"UTF-8\">"
, "<title>Fixture Haddock Documentation</title>"
, "<style>"
, "body { font-family: sans-serif; max-width: 1200px;"
, " margin: 40px auto; padding: 0 20px; }"
, "h1 { border-bottom: 3px solid #3498db; padding-bottom: 10px; }"
, ".stats { background: #ecf0f1; padding: 15px; border-radius: 5px; }"
, ".fixture-list { display: grid;"
, " grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));"
, " gap: 15px; margin: 20px 0; }"
, ".fixture-item { background: #fff; border: 1px solid #ddd;"
, " border-radius: 5px; padding: 15px; }"
, ".fixture-item a { color: #3498db; text-decoration: none; }"
, "footer { margin-top: 40px; border-top: 1px solid #ddd;"
, " padding-top: 20px; color: #7f8c8d; font-size: 0.9em; }"
, "</style></head><body>"
, "<h1>Fixture Haddock Documentation</h1>"
, "<div class=\"stats\">"
, "<strong>Statistics:</strong><br>"
, "Total fixtures: " ++ show totalCount ++ "<br>"
, "Processed: " ++ show (length compiled) ++ "<br>"
, "Skipped: " ++ show skippedCount
, "</div>"
, "<h2>Fixture Documentation</h2>"
, "<div class=\"fixture-list\">"
]
++ map fixtureLink compiled ++
[ "</div>"
, "<footer>Generated by Test.HsBindgen.Fixtures.Haddock</footer>"
, "</body></html>"
]
where
totalCount = length compiled + skippedCount
fixtureLink :: String -> String
fixtureLink name =
let libName = prefix ++ sanitizeLibName name
in "<div class=\"fixture-item\">"
++ "<a href=\"" ++ libName ++ "/index.html\">" ++ name ++ "</a>"
++ "</div>"