aboutsummaryrefslogtreecommitdiff
path: root/src/Text/Pandoc/Templates.hs
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2017-07-19 21:46:28 +0200
committerJohn MacFarlane <jgm@berkeley.edu>2017-07-19 21:46:28 +0200
commit992943d98e14cc2dd249d6279c8c930dddc5547d (patch)
tree1d055b17565d37b6cf251aa3a9ba3a4f6656ac86 /src/Text/Pandoc/Templates.hs
parent2ce6b492e1dce6cddee6dc141bc40bbf67998302 (diff)
downloadpandoc-992943d98e14cc2dd249d6279c8c930dddc5547d.tar.gz
Templates: change signature of getDefaultTemplate.
Now it runs in any instance of PandocMonad, and returns a String rather than an Either value.
Diffstat (limited to 'src/Text/Pandoc/Templates.hs')
-rw-r--r--src/Text/Pandoc/Templates.hs20
1 files changed, 10 insertions, 10 deletions
diff --git a/src/Text/Pandoc/Templates.hs b/src/Text/Pandoc/Templates.hs
index 1a26b7168..516cc4b2f 100644
--- a/src/Text/Pandoc/Templates.hs
+++ b/src/Text/Pandoc/Templates.hs
@@ -38,28 +38,28 @@ module Text.Pandoc.Templates ( module Text.DocTemplates
, getDefaultTemplate
) where
-import qualified Control.Exception as E (IOException, try)
import Control.Monad.Except (throwError)
import Data.Aeson (ToJSON (..))
import qualified Data.Text as T
import System.FilePath ((<.>), (</>))
import Text.DocTemplates (Template, TemplateTarget, applyTemplate,
compileTemplate, renderTemplate, varListToJSON)
-import Text.Pandoc.Class (PandocMonad)
+import Text.Pandoc.Class (PandocMonad(readDataFile))
import Text.Pandoc.Error
-import Text.Pandoc.Shared (readDataFileUTF8)
+import qualified Text.Pandoc.UTF8 as UTF8
-- | Get default template for the specified writer.
-getDefaultTemplate :: (Maybe FilePath) -- ^ User data directory to search first
+getDefaultTemplate :: PandocMonad m
+ => (Maybe FilePath) -- ^ User data directory to search 1st
-> String -- ^ Name of writer
- -> IO (Either E.IOException String)
+ -> m String
getDefaultTemplate user writer = do
let format = takeWhile (`notElem` ("+-" :: String)) writer -- strip off extensions
case format of
- "native" -> return $ Right ""
- "json" -> return $ Right ""
- "docx" -> return $ Right ""
- "fb2" -> return $ Right ""
+ "native" -> return ""
+ "json" -> return ""
+ "docx" -> return ""
+ "fb2" -> return ""
"odt" -> getDefaultTemplate user "opendocument"
"html" -> getDefaultTemplate user "html5"
"docbook" -> getDefaultTemplate user "docbook5"
@@ -70,7 +70,7 @@ getDefaultTemplate user writer = do
"markdown_mmd" -> getDefaultTemplate user "markdown"
"markdown_phpextra" -> getDefaultTemplate user "markdown"
_ -> let fname = "templates" </> "default" <.> format
- in E.try $ readDataFileUTF8 user fname
+ in UTF8.toString <$> readDataFile user fname
-- | Like 'applyTemplate', but runs in PandocMonad and
-- raises an error if compilation fails.