git.iko.soy/typeable/pandoc
on master help sign in
Changed readDataFile to look first in user data directory.
fad620cfiddlosopher
src/Text/Pandoc/Shared.hs+6−3
@@ -118,13 +118,13 @@ import Data.Char ( toLower, toUpper, ord, isLower, isUpper, isAlpha,
118import Data.List ( find, isPrefixOf, intercalate )
118import Data.List ( find, isPrefixOf, intercalate )
119import Network.URI ( parseURI, URI (..), isAllowedInURI )
119import Network.URI ( parseURI, URI (..), isAllowedInURI )
120import System.Directory
120import System.Directory
121+import System.FilePath ( FilePath, (</>) )
121import Prelude hiding ( putStrLn, writeFile, readFile, getContents )
122import Prelude hiding ( putStrLn, writeFile, readFile, getContents )
122import System.IO.UTF8
123import System.IO.UTF8
123import Data.Generics
124import Data.Generics
124import qualified Control.Monad.State as S
125import qualified Control.Monad.State as S
125import Control.Monad (join)
126import Control.Monad (join)
126import Paths_pandoc (getDataFileName)
127import Paths_pandoc (getDataFileName)
127−
128--
128--
129-- List processing
129-- List processing
130--
130--
@@ -1033,6 +1033,9 @@ inDirectory path action = do
1033 setCurrentDirectory oldDir
1033 setCurrentDirectory oldDir
1034 return result
1034 return result
1035
1035
1036+-- | Read file from user data directory or, if not found there, from
1036−-- | Read file from the Cabal data directory.
1037+-- Cabal data directory. On unix the user data directory is @$HOME/.pandoc@.
1037readDataFile :: FilePath -> IO String
1038readDataFile :: FilePath -> IO String
1039+readDataFile fname = do
1040+ userDir <- getAppUserDataDirectory "pandoc"
1038−readDataFile fname = getDataFileName fname >>= readFile
1041+ catch (readFile $ userDir </> fname) (\_ -> getDataFileName fname >>= readFile)
src/Text/Pandoc/Templates.hs+1−18
@@ -49,11 +49,7 @@ import Text.ParserCombinators.Parsec
49import Control.Monad (liftM)
49import Control.Monad (liftM)
50import qualified Control.Exception as E (try, IOException)
50import qualified Control.Exception as E (try, IOException)
51import System.FilePath
51import System.FilePath
52−import System.Directory
53−import Prelude hiding (readFile)
54−import System.IO.UTF8 (readFile)
55import Text.Pandoc.Shared (readDataFile)
52import Text.Pandoc.Shared (readDataFile)
56−import Paths_pandoc
57
53
58-- | Get the default template, either from the application's user data
54-- | Get the default template, either from the application's user data
59-- directory (~/.pandoc on unix) or from the cabal data directory.
55-- directory (~/.pandoc on unix) or from the cabal data directory.
@@ -62,21 +58,8 @@ getDefaultTemplate "native" = return $ Right ""
62getDefaultTemplate "odt" = getDefaultTemplate "opendocument"
58getDefaultTemplate "odt" = getDefaultTemplate "opendocument"
63getDefaultTemplate format = do
59getDefaultTemplate format = do
64 let format' = takeWhile (/='+') format -- strip off "+lhs" if present
60 let format' = takeWhile (/='+') format -- strip off "+lhs" if present
65− ut <- getTemplateFromUserDataDirectory format'
61+ E.try $ readDataFile $ "templates" </> format' <.> "template"
66− case ut of
67− Right t -> return $ Right t
68− Left _ -> getTemplateFromCabalDataDirectory format'
69
62
70−getTemplateFromUserDataDirectory :: String -> IO (Either E.IOException String)
71−getTemplateFromUserDataDirectory format = E.try $ do
72− userDir <- getAppUserDataDirectory "pandoc"
73− let templatePath = userDir </> "templates" </> format <.> "template"
74− readFile templatePath
75−
76−getTemplateFromCabalDataDirectory :: String -> IO (Either E.IOException String)
77−getTemplateFromCabalDataDirectory format = E.try $
78− readDataFile $ "templates" </> format <.> "template"
79−
80-- | Renders a template
63-- | Renders a template
81renderTemplate :: [(String,String)] -- ^ Assoc. list of values for variables
64renderTemplate :: [(String,String)] -- ^ Assoc. list of values for variables
82 -> String -- ^ Template
65 -> String -- ^ Template