summaryrefslogtreecommitdiff
path: root/src/Hakyll/Web/Template/Read.hs
diff options
context:
space:
mode:
authorJasper Van der Jeugt <m@jaspervdj.be>2013-05-07 09:28:09 +0200
committerJasper Van der Jeugt <m@jaspervdj.be>2013-05-07 09:28:09 +0200
commitd32307aa1cbf6718845eeeb2eb6ba3b1c7661bde (patch)
treef982a64bc0cbde3f58e4894af25e19b942a9b5b3 /src/Hakyll/Web/Template/Read.hs
parentcf138a415b0fbfa5153deec693f1310547f359b2 (diff)
downloadhakyll-d32307aa1cbf6718845eeeb2eb6ba3b1c7661bde.tar.gz
Add partials to template system
Diffstat (limited to 'src/Hakyll/Web/Template/Read.hs')
-rw-r--r--src/Hakyll/Web/Template/Read.hs22
1 files changed, 21 insertions, 1 deletions
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