git.iko.soy/typeable/pandoc
on master help sign in
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

commitf0bfbc5508eac083a51ba961bf66225fd526f092 authorfiddlosopher <fiddlosopher@788f1e2b-df1e-0410-8736-df70ead52e1b> dateMon 18 Jan 2010, 07:21 (17 years ago) parent4cdb4c0
2 files changed+13−10
src/Text/Pandoc/ODT.hs+12−9 src/pandoc.hs+1−1
src/Text/Pandoc/ODT.hs+12−9
@@ -42,22 +42,25 @@ import System.Directory
4242import Control.Monad (liftM)
4343
4444-- | Produce an ODT file from OpenDocument XML.
45−saveOpenDocumentAsODT :: FilePath -- ^ Path of user data directory
46− -> FilePath -- ^ Pathname of ODT file to be produced.
47− -> FilePath -- ^ Relative directory of source file.
45+saveOpenDocumentAsODT :: Maybe FilePath -- ^ Path of user data directory
46+ -> FilePath -- ^ Pathname of ODT file to be produced
47+ -> FilePath -- ^ Relative directory of source file
4848 -> Maybe FilePath -- ^ Path specified by --reference-odt
49− -> String -- ^ OpenDocument XML contents.
49+ -> String -- ^ OpenDocument XML contents
5050 -> IO ()
5151saveOpenDocumentAsODT datadir destinationODTPath sourceDirRelative mbRefOdt xml = do
5252 refArchive <- liftM toArchive $
5353 case mbRefOdt of
5454 Just f -> B.readFile f
5555 Nothing -> do
56− let userRefOdt = datadir </> "reference.odt"
57− userRefOdtExists <- doesFileExist userRefOdt
58− if userRefOdtExists
59− then B.readFile userRefOdt
60− else getDataFileName "reference.odt" >>= B.readFile
56+ let defaultODT = getDataFileName "reference.odt" >>= B.readFile
57+ case datadir of
58+ Nothing -> defaultODT
59+ Just d -> do
60+ exists <- doesFileExist (d </> "reference.odt")
61+ if exists
62+ then B.readFile (d </> "reference.odt")
63+ else defaultODT
6164 -- handle pictures
6265 let (newContents, pics) =
6366 case runParser pPictures [] "OpenDocument XML contents" xml of
src/pandoc.hs+1−1
@@ -747,7 +747,7 @@ main = do
747747 let writerOutput = writer writerOptions doc' ++ "\n"
748748
749749 case writerName' of
750− "odt" -> saveOpenDocumentAsODT datadir outputFile sourceDirRelative referenceODT writerOutput
750+ "odt" -> saveOpenDocumentAsODT (Just datadir) outputFile sourceDirRelative referenceODT writerOutput
751751 _ -> if outputFile == "-"
752752 then putStr writerOutput
753753 else writeFile outputFile writerOutput