diff options
author | Jasper Van der Jeugt <jaspervdj@gmail.com> | 2010-12-26 00:09:35 +0100 |
---|---|---|
committer | Jasper Van der Jeugt <jaspervdj@gmail.com> | 2010-12-26 00:09:35 +0100 |
commit | 5bc8028696ae8d5aa2c60db87aea3d00f9d7aebd (patch) | |
tree | cd8d5a87744ad46d0368b971ee0a77efb92b20d8 /src | |
parent | ec85de418b01b4eaefb286a52c050a141204d46f (diff) | |
download | hakyll-5bc8028696ae8d5aa2c60db87aea3d00f9d7aebd.tar.gz |
Add DirectedGraph to DOT module
Diffstat (limited to 'src')
-rw-r--r-- | src/Hakyll/Core/DirectedGraph/Dot.hs | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/src/Hakyll/Core/DirectedGraph/Dot.hs b/src/Hakyll/Core/DirectedGraph/Dot.hs new file mode 100644 index 0000000..8289992 --- /dev/null +++ b/src/Hakyll/Core/DirectedGraph/Dot.hs @@ -0,0 +1,30 @@ +-- | Dump a directed graph in dot format. Used for debugging purposes +-- +module Hakyll.Core.DirectedGraph.Dot + ( toDot + , writeDot + ) where + +import Hakyll.Core.DirectedGraph +import qualified Data.Set as S + +-- | Convert a directed graph into dot format for debugging purposes +-- +toDot :: Ord a + => (a -> String) -- ^ Convert nodes to dot names + -> DirectedGraph a -- ^ Graph to dump + -> String -- ^ Resulting 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 ++ "\";" + +-- | Write out the @.dot@ file to a given file path. See 'toDot' for more +-- information. +-- +writeDot :: Ord a => FilePath -> (a -> String) -> DirectedGraph a -> IO () +writeDot path showTag = writeFile path . toDot showTag |