blob: 49373fde5fd703084c9d268fb80d4c60d269bfe8 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
-- | Module containing the template data structure.
--
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
module Text.Hakyll.Internal.Template.Template
( Template (..)
, TemplateElement (..)
) where
import Control.Applicative ((<$>))
import Data.Binary (Binary, get, getWord8, put, putWord8)
-- | Datatype used for template substitutions.
--
newtype Template = Template { unTemplate :: [TemplateElement] }
deriving (Show, Eq, Binary)
-- | Elements of a template.
--
data TemplateElement = Chunk String
| Identifier String
| EscapeCharacter
deriving (Show, Eq)
instance Binary TemplateElement where
put (Chunk string) = putWord8 0 >> put string
put (Identifier key) = putWord8 1 >> put key
put (EscapeCharacter) = putWord8 2
get = getWord8 >>= \tag ->
case tag of 0 -> Chunk <$> get
1 -> Identifier <$> get
2 -> return EscapeCharacter
_ -> error "Error reading cached template"
|