From 6663735695e4bf023dd1492a4a86259e42f22c77 Mon Sep 17 00:00:00 2001 From: Bergi Date: Sat, 7 Apr 2018 21:29:51 +0200 Subject: [PATCH] more dry code --- lib/Hakyll/Web/Template/Internal.hs | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/lib/Hakyll/Web/Template/Internal.hs b/lib/Hakyll/Web/Template/Internal.hs index 5f2d3dd11..0eea92a77 100644 --- a/lib/Hakyll/Web/Template/Internal.hs +++ b/lib/Hakyll/Web/Template/Internal.hs @@ -167,23 +167,24 @@ applyTemplate' tes context x = go tes debug = compilerDebugEntries ("Hakyll.Web.Template.applyTemplate: " ++ "[ERROR] in 'if' condition on expr '" ++ show e ++ "':") - applyElem (For e b s) = mapError (headMsg:) (applyExpr e) >>= \cf -> case cf of - EmptyField -> expected "list" "boolean" typeMsg - StringField _ -> expected "list" "string" typeMsg - ListField c xs -> mapError (bodyMsg:) $ do - sep <- maybe (return "") go s - bs <- mapM (applyTemplate' b c) xs - return $ intercalate sep bs - LexicalListField mc vs -> mapError (bodyMsg:) do - sep <- maybe (return "") go s - bs <- mapM (\v -> applyTemplate' b (mc context v) x) vs - return $ intercalate sep bs + applyElem (For e b s) = do + bs <- mapError (headMsg:) (applyExpr e) >>= getList + sep <- maybe (return "") go s + return $ intercalate sep bs where + getList EmptyField = expected "list" "boolean" typeMsg + getList (StringField _) = expected "list" "string" typeMsg + getList (ListField c xs) = mapError (bodyMsg:) $ + mapM (applyTemplate' b c) xs + getList (LexicalListField mc vs) = mapError (bodyMsg:) $ + mapM (\v -> applyTemplate' b (mc context v) x) vs + headMsg = "In expr '$for(" ++ show e ++ ")$'" typeMsg = "loop expr '" ++ show e ++ "'" bodyMsg = "In loop context of '$for(" ++ show e ++ ")$'" - applyElem (Partial e) = applyStringExpr (headMsg:) typeMsg e >>= \p -> + applyElem (Partial e) = do + p <- applyStringExpr (headMsg:) typeMsg e mapError (inclMsg:) $ do tpl' <- loadBody (fromFilePath p) itemBody <$> applyTemplate tpl' context x