From d32307aa1cbf6718845eeeb2eb6ba3b1c7661bde Mon Sep 17 00:00:00 2001 From: Jasper Van der Jeugt Date: Tue, 7 May 2013 09:28:09 +0200 Subject: Add partials to template system --- src/Hakyll/Web/Template/Read.hs | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) (limited to 'src/Hakyll/Web/Template/Read.hs') 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) -------------------------------------------------------------------------------- @@ -64,6 +64,15 @@ for = try $ do return $ For i body sep +-------------------------------------------------------------------------------- +partial :: Parser TemplateElement +partial = try $ do + void $ string "$partial(" + i <- stringLiteral + void $ string ")$" + return $ Partial i + + -------------------------------------------------------------------------------- key :: Parser TemplateElement key = try $ do @@ -71,3 +80,14 @@ key = try $ do 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 -- cgit v1.2.3