diff options
author | Jasper Van der Jeugt <m@jaspervdj.be> | 2014-01-19 21:24:52 +0100 |
---|---|---|
committer | Jasper Van der Jeugt <m@jaspervdj.be> | 2014-01-19 21:25:18 +0100 |
commit | 677cca05784a0409e91ee2b8c354f148772e5d57 (patch) | |
tree | 14cedf908b3b3219eaeaf07c1aebed0af85e59bc /src/Hakyll/Web/Template/Read.hs | |
parent | c024ed8a93b56bca0cad152c9fb3b52d280a304d (diff) | |
download | hakyll-677cca05784a0409e91ee2b8c354f148772e5d57.tar.gz |
Add IsString instance for Template
Closes #150
Diffstat (limited to 'src/Hakyll/Web/Template/Read.hs')
-rw-r--r-- | src/Hakyll/Web/Template/Read.hs | 93 |
1 files changed, 0 insertions, 93 deletions
diff --git a/src/Hakyll/Web/Template/Read.hs b/src/Hakyll/Web/Template/Read.hs deleted file mode 100644 index 2421b2d..0000000 --- a/src/Hakyll/Web/Template/Read.hs +++ /dev/null @@ -1,93 +0,0 @@ --------------------------------------------------------------------------------- --- | Read templates in Hakyll's native format -module Hakyll.Web.Template.Read - ( readTemplate - ) where - - --------------------------------------------------------------------------------- -import Control.Applicative ((<$), (<$>)) -import Control.Monad (void) -import Text.Parsec -import Text.Parsec.String - - --------------------------------------------------------------------------------- -import Hakyll.Core.Util.Parser -import Hakyll.Web.Template.Internal - - --------------------------------------------------------------------------------- -readTemplate :: String -> Template -readTemplate input = case parse template "" input of - Left err -> error $ "Cannot parse template: " ++ show err - Right t -> t - - --------------------------------------------------------------------------------- -template :: Parser Template -template = Template <$> - (many1 $ chunk <|> escaped <|> conditional <|> for <|> partial <|> key) - - --------------------------------------------------------------------------------- -chunk :: Parser TemplateElement -chunk = Chunk <$> (many1 $ noneOf "$") - - --------------------------------------------------------------------------------- -escaped :: Parser TemplateElement -escaped = Escaped <$ (try $ string "$$") - - --------------------------------------------------------------------------------- -conditional :: Parser TemplateElement -conditional = try $ do - void $ string "$if(" - i <- metadataKey - void $ string ")$" - thenBranch <- template - elseBranch <- optionMaybe $ try (string "$else$") >> template - void $ string "$endif$" - return $ If i thenBranch elseBranch - - --------------------------------------------------------------------------------- -for :: Parser TemplateElement -for = try $ do - void $ string "$for(" - i <- metadataKey - void $ string ")$" - body <- template - sep <- optionMaybe $ try (string "$sep$") >> template - void $ string "$endfor$" - 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 - 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 |