diff options
author | Jasper Van der Jeugt <m@jaspervdj.be> | 2013-05-07 09:28:09 +0200 |
---|---|---|
committer | Jasper Van der Jeugt <m@jaspervdj.be> | 2013-05-07 09:28:09 +0200 |
commit | d32307aa1cbf6718845eeeb2eb6ba3b1c7661bde (patch) | |
tree | f982a64bc0cbde3f58e4894af25e19b942a9b5b3 /src/Hakyll/Web/Template/Read.hs | |
parent | cf138a415b0fbfa5153deec693f1310547f359b2 (diff) | |
download | hakyll-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.hs | 22 |
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 |