module Hakyll.Core.DirectedGraph.Dot
( toDot
, writeDot
) where
import Hakyll.Core.DirectedGraph
import qualified Data.Set as S
toDot :: Ord a
=> (a -> String)
-> DirectedGraph a
-> String
toDot showTag graph = unlines $ concat
[ return "digraph dependencies {"
, concatMap showNode (S.toList $ nodes graph)
, return "}"
]
where
showNode node = map (showEdge node) $ S.toList $ neighbours node graph
showEdge x y = " \"" ++ showTag x ++ "\" -> \"" ++ showTag y ++ "\";"
writeDot :: Ord a => FilePath -> (a -> String) -> DirectedGraph a -> IO ()
writeDot path showTag = writeFile path . toDot showTag