aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJohn MacFarlane <fiddlosopher@gmail.com>2012-12-29 18:45:20 -0800
committerJohn MacFarlane <fiddlosopher@gmail.com>2012-12-29 18:45:20 -0800
commitc2fe3aae64dd9e5ea5d05827240450522b0ff766 (patch)
tree6c91978b8e8091355a225f437cf05e582fa4bb7c /src
parent2f984b607469ea8228ea6c1aa2c52aec5845faa3 (diff)
downloadpandoc-c2fe3aae64dd9e5ea5d05827240450522b0ff766.tar.gz
Made `embed_data_files` flag work.
Diffstat (limited to 'src')
-rw-r--r--src/Text/Pandoc/Shared.hs14
1 files changed, 11 insertions, 3 deletions
diff --git a/src/Text/Pandoc/Shared.hs b/src/Text/Pandoc/Shared.hs
index 71bdca9dd..7bd35b138 100644
--- a/src/Text/Pandoc/Shared.hs
+++ b/src/Text/Pandoc/Shared.hs
@@ -1,4 +1,4 @@
-{-# LANGUAGE DeriveDataTypeable, CPP #-}
+{-# LANGUAGE DeriveDataTypeable, CPP, TemplateHaskell #-}
{-
Copyright (C) 2006-2010 John MacFarlane <jgm@berkeley.edu>
@@ -504,12 +504,20 @@ inDirectory path action = do
setCurrentDirectory oldDir
return result
+#ifdef EMBED_DATA_FILES
+dataFiles :: [(FilePath, B.ByteString)]
+dataFiles = $(embedDir "data")
+#endif
+
readDefaultDataFile :: FilePath -> IO B.ByteString
readDefaultDataFile fname =
#ifdef EMBED_DATA_FILES
- TODO
+ case lookup fname dataFiles of
+ Nothing -> ioError $ userError
+ $ "Data file `" ++ fname ++ "' does not exist"
+ Just contents -> return contents
#else
- getDataFileName fname >>= B.readFile
+ getDataFileName ("data" </> fname) >>= B.readFile
#endif
-- | Read file from specified user data directory or, if not found there, from