From f0bfbc5508eac083a51ba961bf66225fd526f092 Mon Sep 17 00:00:00 2001 From: fiddlosopher Date: Mon, 18 Jan 2010 07:21:10 +0000 Subject: Made userdir arg of saveDocumentAsODT a Maybe. This way it's consistent with other data file retrieval functions. git-svn-id: https://pandoc.googlecode.com/svn/trunk@1823 788f1e2b-df1e-0410-8736-df70ead52e1b --- src/Text/Pandoc/ODT.hs | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) (limited to 'src/Text') diff --git a/src/Text/Pandoc/ODT.hs b/src/Text/Pandoc/ODT.hs index bd497d0b3..6d602fb2a 100644 --- a/src/Text/Pandoc/ODT.hs +++ b/src/Text/Pandoc/ODT.hs @@ -42,22 +42,25 @@ import System.Directory import Control.Monad (liftM) -- | Produce an ODT file from OpenDocument XML. -saveOpenDocumentAsODT :: FilePath -- ^ Path of user data directory - -> FilePath -- ^ Pathname of ODT file to be produced. - -> FilePath -- ^ Relative directory of source file. +saveOpenDocumentAsODT :: Maybe FilePath -- ^ Path of user data directory + -> FilePath -- ^ Pathname of ODT file to be produced + -> FilePath -- ^ Relative directory of source file -> Maybe FilePath -- ^ Path specified by --reference-odt - -> String -- ^ OpenDocument XML contents. + -> String -- ^ OpenDocument XML contents -> IO () saveOpenDocumentAsODT datadir destinationODTPath sourceDirRelative mbRefOdt xml = do refArchive <- liftM toArchive $ case mbRefOdt of Just f -> B.readFile f Nothing -> do - let userRefOdt = datadir "reference.odt" - userRefOdtExists <- doesFileExist userRefOdt - if userRefOdtExists - then B.readFile userRefOdt - else getDataFileName "reference.odt" >>= B.readFile + let defaultODT = getDataFileName "reference.odt" >>= B.readFile + case datadir of + Nothing -> defaultODT + Just d -> do + exists <- doesFileExist (d "reference.odt") + if exists + then B.readFile (d "reference.odt") + else defaultODT -- handle pictures let (newContents, pics) = case runParser pPictures [] "OpenDocument XML contents" xml of -- cgit v1.2.3