summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorfiddlosopher <fiddlosopher@788f1e2b-df1e-0410-8736-df70ead52e1b>2010-01-18 07:21:10 +0000
committerfiddlosopher <fiddlosopher@788f1e2b-df1e-0410-8736-df70ead52e1b>2010-01-18 07:21:10 +0000
commitf0bfbc5508eac083a51ba961bf66225fd526f092 (patch)
treef401b843ca322dfbacb19d60f72271759f47e9e8
parent4cdb4c0b365a16efe2a6b7111a82cc1a723c0750 (diff)
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
-rw-r--r--src/Text/Pandoc/ODT.hs21
-rw-r--r--src/pandoc.hs2
2 files changed, 13 insertions, 10 deletions
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
diff --git a/src/pandoc.hs b/src/pandoc.hs
index 6ca3e3423..f64f218fe 100644
--- a/src/pandoc.hs
+++ b/src/pandoc.hs
@@ -747,7 +747,7 @@ main = do
let writerOutput = writer writerOptions doc' ++ "\n"
case writerName' of
- "odt" -> saveOpenDocumentAsODT datadir outputFile sourceDirRelative referenceODT writerOutput
+ "odt" -> saveOpenDocumentAsODT (Just datadir) outputFile sourceDirRelative referenceODT writerOutput
_ -> if outputFile == "-"
then putStr writerOutput
else writeFile outputFile writerOutput