summaryrefslogtreecommitdiff
path: root/lib/Hakyll/Web/Template.hs
diff options
context:
space:
mode:
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 |]