summaryrefslogtreecommitdiff
path: root/src/Hakyll/Web/Template
diff options
context:
space:
mode:
Diffstat (limited to 'src/Hakyll/Web/Template')
-rw-r--r--src/Hakyll/Web/Template/Internal.hs5
-rw-r--r--src/Hakyll/Web/Template/Read.hs22
2 files changed, 25 insertions, 2 deletions
diff --git a/src/Hakyll/Web/Template/Internal.hs b/src/Hakyll/Web/Template/Internal.hs
index 1c81670..138010e 100644
--- a/src/Hakyll/Web/Template/Internal.hs
+++ b/src/Hakyll/Web/Template/Internal.hs
@@ -39,6 +39,7 @@ data TemplateElement
| Escaped
| If String Template (Maybe Template) -- key, then branch, else branch
| For String Template (Maybe Template) -- key, body, separator
+ | Partial String -- filename
deriving (Show, Eq, Typeable)
@@ -49,12 +50,14 @@ instance Binary TemplateElement where
put (Escaped) = putWord8 2
put (If key t f) = putWord8 3 >> put key >> put t >> put f
put (For key b s) = putWord8 4 >> put key >> put b >> put s
+ put (Partial p) = putWord8 5 >> put p
get = getWord8 >>= \tag -> case tag of
0 -> Chunk <$> get
1 -> Key <$> get
2 -> pure Escaped
- 3 -> If <$> get <*> get <*> get
+ 3 -> If <$> get <*> get <*> get
4 -> For <$> get <*> get <*> get
+ 5 -> Partial <$> get
_ -> error $
"Hakyll.Web.Template.Internal: Error reading cached template"
diff --git a/src/Hakyll/Web/Template/Read.hs b/src/Hakyll/Web/Template/Read.hs
index 2dd0fc5..bb5c8c2 100644
--- a/src/Hakyll/Web/Template/Read.hs
+++ b/src/Hakyll/Web/Template/Read.hs
@@ -27,7 +27,7 @@ readTemplate input = case parse template "" input of
--------------------------------------------------------------------------------
template :: Parser Template
template = Template <$>
- (many1 $ chunk <|> escaped <|> conditional <|> for <|> key)
+ (many1 $ chunk <|> escaped <|> conditional <|> for <|> partial <|> key)
--------------------------------------------------------------------------------
@@ -65,9 +65,29 @@ for = try $ do
--------------------------------------------------------------------------------
+partial :: Parser TemplateElement
+partial = try $ do
+ void $ string "$partial("
+ i <- stringLiteral
+ void $ string ")$"
+ return $ Partial i
+
+
+--------------------------------------------------------------------------------
key :: Parser TemplateElement
key = try $ do
void $ char '$'
k <- metadataKey
void $ char '$'
return $ Key k
+
+
+--------------------------------------------------------------------------------
+stringLiteral :: Parser String
+stringLiteral = do
+ void $ char '\"'
+ str <- many $ do
+ x <- noneOf "\""
+ if x == '\\' then anyChar else return x
+ void $ char '\"'
+ return str