From f1407848708c9d76f0fa3a95e6af7ffc13e158d6 Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Fri, 14 Jul 2017 16:24:30 +0200 Subject: Class: added addToFileTree --- src/Text/Pandoc/Class.hs | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'src/Text/Pandoc') diff --git a/src/Text/Pandoc/Class.hs b/src/Text/Pandoc/Class.hs index 120ba8fee..d8505e0b1 100644 --- a/src/Text/Pandoc/Class.hs +++ b/src/Text/Pandoc/Class.hs @@ -60,6 +60,7 @@ module Text.Pandoc.Class ( PandocMonad(..) , PandocPure(..) , FileTree(..) , FileInfo(..) + , addToFileTree , runIO , runIOorExplode , runPure @@ -479,6 +480,13 @@ newtype FileTree = FileTree {unFileTree :: M.Map FilePath FileInfo} getFileInfo :: FilePath -> FileTree -> Maybe FileInfo getFileInfo fp tree = M.lookup fp $ unFileTree tree +addToFileTree :: FileTree -> FilePath -> IO FileTree +addToFileTree (FileTree treemap) fp = do + contents <- B.readFile fp + mtime <- IO.getModificationTime fp + return $ FileTree $ + M.insert fp FileInfo{ infoFileMTime = mtime + , infoFileContents = contents } treemap newtype PandocPure a = PandocPure { unPandocPure :: ExceptT PandocError -- cgit v1.2.3