summaryrefslogtreecommitdiff
path: root/src/Hakyll/Web/Template/Internal.hs
diff options
context:
space:
mode:
authorIvan N. Veselov <veselov@gmail.com>2013-05-03 19:10:57 +0300
committerIvan N. Veselov <veselov@gmail.com>2013-05-03 19:10:57 +0300
commitf86b9c5b0cd702788cfb1cc4db9b63f72c7105eb (patch)
tree9826732e7d585a237e05f416ac20511b0ac97225 /src/Hakyll/Web/Template/Internal.hs
parent617322ae8ce039fcd36a7a7629a822522454a1af (diff)
downloadhakyll-f86b9c5b0cd702788cfb1cc4db9b63f72c7105eb.tar.gz
Added support for "$if$" statement in templates.
Diffstat (limited to 'src/Hakyll/Web/Template/Internal.hs')
-rw-r--r--src/Hakyll/Web/Template/Internal.hs12
1 files changed, 7 insertions, 5 deletions
diff --git a/src/Hakyll/Web/Template/Internal.hs b/src/Hakyll/Web/Template/Internal.hs
index e264731..0bd999e 100644
--- a/src/Hakyll/Web/Template/Internal.hs
+++ b/src/Hakyll/Web/Template/Internal.hs
@@ -9,7 +9,7 @@ module Hakyll.Web.Template.Internal
--------------------------------------------------------------------------------
-import Control.Applicative ((<$>))
+import Control.Applicative (pure, (<$>), (<*>))
import Data.Binary (Binary, get, getWord8, put, putWord8)
import Data.Typeable (Typeable)
@@ -38,18 +38,20 @@ data TemplateElement
= Chunk String
| Key String
| Escaped
+ | If String Template (Maybe Template) -- key, then branch, else branch
deriving (Show, Eq, Typeable)
-
--------------------------------------------------------------------------------
instance Binary TemplateElement where
- put (Chunk string) = putWord8 0 >> put string
- put (Key key) = putWord8 1 >> put key
+ put (Chunk string) = putWord8 0 >> put string
+ put (Key key) = putWord8 1 >> put key
put (Escaped) = putWord8 2
+ put (If key t f) = putWord8 3 >> put key >> put t >> put f
get = getWord8 >>= \tag -> case tag of
0 -> Chunk <$> get
1 -> Key <$> get
- 2 -> return Escaped
+ 2 -> pure Escaped
+ 3 -> If <$> get <*> get <*> get
_ -> error $ "Hakyll.Web.Template.Internal: "
++ "Error reading cached template"