diff options
author | John MacFarlane <jgm@berkeley.edu> | 2017-08-10 23:16:10 -0700 |
---|---|---|
committer | John MacFarlane <jgm@berkeley.edu> | 2017-08-10 23:16:10 -0700 |
commit | 13abd97ac0dad1162a6779775207a3db06418ce9 (patch) | |
tree | fad3253a9f471ba17a342f4f53cf2ca7020c213a /src/Text | |
parent | 6aaf8f4770916fcef433d0078502d674a1c97fc7 (diff) | |
download | pandoc-13abd97ac0dad1162a6779775207a3db06418ce9.tar.gz |
Class: add setUserDataDir and getUserDataDir.
* Add stUserDataDir to CommonState.
* Rename stUserDataDir/stCabalDataDir in PureState to
stUserDataFiles/stCabalDataFiles.
Diffstat (limited to 'src/Text')
-rw-r--r-- | src/Text/Pandoc/Class.hs | 26 |
1 files changed, 21 insertions, 5 deletions
diff --git a/src/Text/Pandoc/Class.hs b/src/Text/Pandoc/Class.hs index cefc8ee2c..8ef7f3c66 100644 --- a/src/Text/Pandoc/Class.hs +++ b/src/Text/Pandoc/Class.hs @@ -56,6 +56,8 @@ module Text.Pandoc.Class ( PandocMonad(..) , getMediaBag , setMediaBag , insertMedia + , setUserDataDir + , getUserDataDir , fetchItem , getInputFiles , getOutputFile @@ -266,6 +268,8 @@ readFileFromDirs (d:ds) f = catchError -- functions like 'setVerbosity' and 'withMediaBag' should be used. data CommonState = CommonState { stLog :: [LogMessage] -- ^ A list of log messages in reverse order + , stUserDataDir :: Maybe FilePath + -- ^ Directory to search for data files , stMediaBag :: MediaBag -- ^ Media parsed from binary containers , stInputFiles :: Maybe [FilePath] @@ -284,6 +288,7 @@ data CommonState = CommonState { stLog :: [LogMessage] instance Default CommonState where def = CommonState { stLog = [] + , stUserDataDir = Nothing , stMediaBag = mempty , stInputFiles = Nothing , stOutputFile = Nothing @@ -359,6 +364,17 @@ parseURIReference' s = | null (uriScheme u) -> Just u -- protocol-relative _ -> Nothing +-- | Set the user data directory in common state. +setUserDataDir :: PandocMonad m + => Maybe FilePath + -> m () +setUserDataDir mbfp = modifyCommonState $ \st -> st{ stUserDataDir = mbfp } + +-- | Get the user data directory from common state. +getUserDataDir :: PandocMonad m + => m (Maybe FilePath) +getUserDataDir = getsCommonState stUserDataDir + -- | Fetch an image or other item from the local filesystem or the net. -- Returns raw content and maybe mime type. fetchItem :: PandocMonad m @@ -497,8 +513,8 @@ data PureState = PureState { stStdGen :: StdGen , stReferenceDocx :: Archive , stReferenceODT :: Archive , stFiles :: FileTree - , stUserDataDir :: FileTree - , stCabalDataDir :: FileTree + , stUserDataFiles :: FileTree + , stCabalDataFiles :: FileTree } instance Default PureState where @@ -511,8 +527,8 @@ instance Default PureState where , stReferenceDocx = emptyArchive , stReferenceODT = emptyArchive , stFiles = mempty - , stUserDataDir = mempty - , stCabalDataDir = mempty + , stUserDataFiles = mempty + , stCabalDataFiles = mempty } @@ -614,7 +630,7 @@ instance PandocMonad PandocPure where let fname' = if fname == "MANUAL.txt" then fname else "data" </> fname readFileStrict fname' readDataFile (Just userDir) fname = do - userDirFiles <- getsPureState stUserDataDir + userDirFiles <- getsPureState stUserDataFiles case infoFileContents <$> getFileInfo (userDir </> fname) userDirFiles of Just bs -> return bs Nothing -> readDataFile Nothing fname |