git.iko.soy/typeable/pandoc
on master help sign in
Add getFileName to PandocMonad.

We need this for getDefaultDataFile.

commit6c5952e746c8d6cbd9bb921b444b6314daacd9ac authorJohn MacFarlane <jgm@berkeley.edu> dateFri 11 Aug 2017, 23:09 (9 years ago) parent198f209
1 file changed+16−2
src/Text/Pandoc/Class.hs+16−2
src/Text/Pandoc/Class.hs+16−2
@@ -142,7 +142,7 @@ import qualified Debug.Trace
142142#ifdef EMBED_DATA_FILES
143143import Text.Pandoc.Data (dataFiles)
144144#else
145−import Paths_pandoc (getDataFileName)
145+import qualified Paths_pandoc as Paths
146146#endif
147147
148148-- | The PandocMonad typeclass contains all the potentially
@@ -177,6 +177,8 @@ class (Functor m, Applicative m, Monad m, MonadError PandocError m)
177177 glob :: String -> m [FilePath]
178178 -- | Returns True if file exists.
179179 fileExists :: FilePath -> m Bool
180+ -- | Returns the path of data file.
181+ getDataFileName :: FilePath -> m FilePath
180182 -- | Return the modification time of a file.
181183 getModificationTime :: FilePath -> m UTCTime
182184 -- | Get the value of the 'CommonState' used by all instances
@@ -419,7 +421,12 @@ instance PandocMonad PandocIO where
419421
420422 glob = liftIOError IO.glob
421423 fileExists = liftIOError Directory.doesFileExist
422− getModificationTime fp = liftIOError IO.getModificationTime fp
424+#ifdef EMBED_DATA_FILES
425+ getDataFileName = return
426+#else
427+ getDataFileName = liftIOError Paths.getDataFileName
428+#endif
429+ getModificationTime = liftIOError IO.getModificationTime
423430 getCommonState = PandocIO $ lift get
424431 putCommonState x = PandocIO $ lift $ put x
425432 logOutput msg = liftIO $ do
@@ -817,6 +824,8 @@ instance PandocMonad PandocPure where
817824 Nothing -> return False
818825 Just _ -> return True
819826
827+ getDataFileName fp = return $ "data/" ++ fp
828+
820829 getModificationTime fp = do
821830 fps <- getsPureState stFiles
822831 case infoFileMTime <$> getFileInfo fp fps of
@@ -840,6 +849,7 @@ instance PandocMonad m => PandocMonad (ParsecT s st m) where
840849 readFileStrict = lift . readFileStrict
841850 glob = lift . glob
842851 fileExists = lift . fileExists
852+ getDataFileName = lift . getDataFileName
843853 getModificationTime = lift . getModificationTime
844854 getCommonState = lift getCommonState
845855 putCommonState = lift . putCommonState
@@ -868,6 +878,7 @@ instance PandocMonad m => PandocMonad (ReaderT r m) where
868878 readFileStrict = lift . readFileStrict
869879 glob = lift . glob
870880 fileExists = lift . fileExists
881+ getDataFileName = lift . getDataFileName
871882 getModificationTime = lift . getModificationTime
872883 getCommonState = lift getCommonState
873884 putCommonState = lift . putCommonState
@@ -884,6 +895,7 @@ instance (PandocMonad m, Monoid w) => PandocMonad (WriterT w m) where
884895 readFileStrict = lift . readFileStrict
885896 glob = lift . glob
886897 fileExists = lift . fileExists
898+ getDataFileName = lift . getDataFileName
887899 getModificationTime = lift . getModificationTime
888900 getCommonState = lift getCommonState
889901 putCommonState = lift . putCommonState
@@ -900,6 +912,7 @@ instance (PandocMonad m, Monoid w) => PandocMonad (RWST r w st m) where
900912 readFileStrict = lift . readFileStrict
901913 glob = lift . glob
902914 fileExists = lift . fileExists
915+ getDataFileName = lift . getDataFileName
903916 getModificationTime = lift . getModificationTime
904917 getCommonState = lift getCommonState
905918 putCommonState = lift . putCommonState
@@ -916,6 +929,7 @@ instance PandocMonad m => PandocMonad (StateT st m) where
916929 readFileStrict = lift . readFileStrict
917930 glob = lift . glob
918931 fileExists = lift . fileExists
932+ getDataFileName = lift . getDataFileName
919933 getModificationTime = lift . getModificationTime
920934 getCommonState = lift getCommonState
921935 putCommonState = lift . putCommonState