@@ -0,0 +1,30 @@
1+-- | Dump a directed graph in dot format. Used for debugging purposes
3+module Hakyll.Core.DirectedGraph.Dot
8+import Hakyll.Core.DirectedGraph
9+import qualified Data.Set as S
11+-- | Convert a directed graph into dot format for debugging purposes
14+ => (a -> String) -- ^ Convert nodes to dot names
15+ -> DirectedGraph a -- ^ Graph to dump
16+ -> String -- ^ Resulting string
17+toDot showTag graph = unlines $ concat
18+ [ return "digraph dependencies {"
19+ , concatMap showNode (S.toList $ nodes graph)
23+ showNode node = map (showEdge node) $ S.toList $ neighbours node graph
24+ showEdge x y = " \"" ++ showTag x ++ "\" -> \"" ++ showTag y ++ "\";"
26+-- | Write out the @.dot@ file to a given file path. See 'toDot' for more
29+writeDot :: Ord a => FilePath -> (a -> String) -> DirectedGraph a -> IO ()
30+writeDot path showTag = writeFile path . toDot showTag