summaryrefslogtreecommitdiff
path: root/lib/Hakyll/Web/Template.hs
diff options
context:
space:
mode:
authorJasper Van der Jeugt <m@jaspervdj.be>2019-08-30 11:46:13 +0200
committerGitHub <noreply@github.com>2019-08-30 11:46:13 +0200
commit036c583ea243869f05a5a311c90b94943a2b635c (patch)
treeaadee7988980544f84b83d808707080481568cc5 /lib/Hakyll/Web/Template.hs
parent779fa66c7b1719e071dc3f4d38a4cc2feb9492c6 (diff)
downloadhakyll-036c583ea243869f05a5a311c90b94943a2b635c.tar.gz
Improve error messages
Diffstat (limited to 'lib/Hakyll/Web/Template.hs')
-rw-r--r--lib/Hakyll/Web/Template.hs26
1 files changed, 24 insertions, 2 deletions
diff --git a/lib/Hakyll/Web/Template.hs b/lib/Hakyll/Web/Template.hs
index a436106..3ef79f9 100644
--- a/lib/Hakyll/Web/Template.hs
+++ b/lib/Hakyll/Web/Template.hs
@@ -138,19 +138,41 @@
-- > 3...2...1
-- > </p>
--
+{-# LANGUAGE TemplateHaskell #-}
module Hakyll.Web.Template
( Template
- , template
- , readTemplateElems
, templateBodyCompiler
, templateCompiler
, applyTemplate
, loadAndApplyTemplate
, applyAsTemplate
, readTemplate
+ , compileTemplateItem
, unsafeReadTemplateFile
+ , embedTemplate
) where
--------------------------------------------------------------------------------
import Hakyll.Web.Template.Internal
+
+
+--------------------------------------------------------------------------------
+import Data.FileEmbed (embedFile)
+import qualified Data.Text as T
+import qualified Data.Text.Encoding as T
+import Language.Haskell.TH (Exp, Q)
+
+
+--------------------------------------------------------------------------------
+-- | Embed template allows you embed a template within the Haskell binary.
+-- Example:
+--
+-- > myTemplate :: Template
+-- > myTemplate = $(embedTemplate "test.html")
+embedTemplate :: FilePath -> Q Exp
+embedTemplate filePath = [|
+ let source = T.unpack $ T.decodeUtf8 $(embedFile filePath) in
+ case parseTemplateElemsFile filePath source of
+ Left err -> error err
+ Right tpl -> template filePath tpl |]