aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorfiddlosopher <fiddlosopher@788f1e2b-df1e-0410-8736-df70ead52e1b>2010-01-18 07:01:29 +0000
committerfiddlosopher <fiddlosopher@788f1e2b-df1e-0410-8736-df70ead52e1b>2010-01-18 07:01:29 +0000
commitb412a9cf4a3bf841f4fb4fb1bf63590f3c9c43e6 (patch)
treec2a9d1a07e8e1f534f5b33655b865900b5929c3c
parent9fed26181f7cc8aa0f3bd2a01332204389c8979c (diff)
downloadpandoc-b412a9cf4a3bf841f4fb4fb1bf63590f3c9c43e6.tar.gz
Made user directory a Maybe in readFile, s5HeaderIncludes, laTeXMathML.
This is more uniform, and calling libraries can always disable searching of user directories for overrides. git-svn-id: https://pandoc.googlecode.com/svn/trunk@1821 788f1e2b-df1e-0410-8736-df70ead52e1b
-rw-r--r--src/Text/Pandoc/LaTeXMathML.hs2
-rw-r--r--src/Text/Pandoc/Shared.hs10
-rw-r--r--src/Text/Pandoc/Templates.hs5
-rw-r--r--src/Text/Pandoc/Writers/S5.hs6
-rw-r--r--src/pandoc.hs4
5 files changed, 13 insertions, 14 deletions
diff --git a/src/Text/Pandoc/LaTeXMathML.hs b/src/Text/Pandoc/LaTeXMathML.hs
index 362e7b084..0c8f74bdf 100644
--- a/src/Text/Pandoc/LaTeXMathML.hs
+++ b/src/Text/Pandoc/LaTeXMathML.hs
@@ -5,7 +5,7 @@ import System.FilePath ( (</>) )
import Text.Pandoc.Shared (readDataFile)
-- | String containing LaTeXMathML javascript.
-latexMathMLScript :: FilePath -> IO String
+latexMathMLScript :: Maybe FilePath -> IO String
latexMathMLScript datadir = do
jsCom <- readDataFile datadir $ "data" </> "LaTeXMathML.js.comment"
jsPacked <- readDataFile datadir $ "data" </> "LaTeXMathML.js.packed"
diff --git a/src/Text/Pandoc/Shared.hs b/src/Text/Pandoc/Shared.hs
index 5657321d8..14086c20f 100644
--- a/src/Text/Pandoc/Shared.hs
+++ b/src/Text/Pandoc/Shared.hs
@@ -1046,7 +1046,9 @@ inDirectory path action = do
-- | Read file from specified user data directory or, if not found there, from
-- Cabal data directory.
-readDataFile :: FilePath -> FilePath -> IO String
-readDataFile userDir fname = catch
- (readFile $ userDir </> fname)
- (\_ -> getDataFileName fname >>= readFile)
+readDataFile :: Maybe FilePath -> FilePath -> IO String
+readDataFile userDir fname =
+ case userDir of
+ Nothing -> getDataFileName fname >>= readFile
+ Just u -> catch (readFile $ u </> fname)
+ (\_ -> getDataFileName fname >>= readFile)
diff --git a/src/Text/Pandoc/Templates.hs b/src/Text/Pandoc/Templates.hs
index 9f677608d..8fb155c25 100644
--- a/src/Text/Pandoc/Templates.hs
+++ b/src/Text/Pandoc/Templates.hs
@@ -84,7 +84,6 @@ import Text.Pandoc.Shared (readDataFile)
import Prelude hiding ( readFile )
import System.IO.UTF8 ( readFile )
#endif
-import Paths_pandoc (getDataFileName)
-- | Get default template for the specified writer.
getDefaultTemplate :: (Maybe FilePath) -- ^ User data directory to search first
@@ -96,9 +95,7 @@ getDefaultTemplate user "odt" = getDefaultTemplate user "opendocument"
getDefaultTemplate user writer = do
let format = takeWhile (/='+') writer -- strip off "+lhs" if present
let fname = "templates" </> format <.> "template"
- E.try $ case user of
- Just d -> readDataFile d fname
- Nothing -> getDataFileName fname >>= readFile
+ E.try $ readDataFile user fname
data TemplateState = TemplateState Int [(String,String)]
diff --git a/src/Text/Pandoc/Writers/S5.hs b/src/Text/Pandoc/Writers/S5.hs
index c5b6b05ce..1dff06e62 100644
--- a/src/Text/Pandoc/Writers/S5.hs
+++ b/src/Text/Pandoc/Writers/S5.hs
@@ -44,7 +44,7 @@ import Text.XHtml.Strict
import System.FilePath ( (</>) )
import Data.List ( intercalate )
-s5HeaderIncludes :: FilePath -> IO String
+s5HeaderIncludes :: Maybe FilePath -> IO String
s5HeaderIncludes datadir = do
c <- s5CSS datadir
j <- s5Javascript datadir
@@ -53,14 +53,14 @@ s5HeaderIncludes datadir = do
s5Meta :: String
s5Meta = "<!-- configuration parameters -->\n<meta name=\"defaultView\" content=\"slideshow\" />\n<meta name=\"controlVis\" content=\"hidden\" />\n"
-s5Javascript :: FilePath -> IO String
+s5Javascript :: Maybe FilePath -> IO String
s5Javascript datadir = do
jsCom <- readDataFile datadir $ "s5" </> "default" </> "slides.js.comment"
jsPacked <- readDataFile datadir $ "s5" </> "default" </> "slides.js.packed"
return $ "<script type=\"text/javascript\">\n" ++ jsCom ++ jsPacked ++
"</script>\n"
-s5CSS :: FilePath -> IO String
+s5CSS :: Maybe FilePath -> IO String
s5CSS datadir = do
s5CoreCSS <- readDataFile datadir $ "s5" </> "default" </> "s5-core.css"
s5FramingCSS <- readDataFile datadir $ "s5" </> "default" </> "framing.css"
diff --git a/src/pandoc.hs b/src/pandoc.hs
index 4504daec9..6ca3e3423 100644
--- a/src/pandoc.hs
+++ b/src/pandoc.hs
@@ -668,13 +668,13 @@ main = do
variables' <- if writerName' == "s5" && standalone'
then do
- inc <- s5HeaderIncludes datadir
+ inc <- s5HeaderIncludes (Just datadir)
return $ ("header-includes", inc) : variables
else return variables
variables'' <- case mathMethod of
LaTeXMathML Nothing -> do
- s <- latexMathMLScript datadir
+ s <- latexMathMLScript (Just datadir)
return $ ("latexmathml-script", s) : variables'
_ -> return variables'