@@ -116,7 +116,8 @@ renderM :: Text -> LarcenyHspecM Text
116116renderM templateText = do
117117 (LarcenyHspecState _ (LarcenyState p s l o)) <- S. get
118118 let tpl = parseWithOverrides o (LT. fromStrict templateText)
119- liftIO $ evalStateT (runTemplate tpl p s l) ()
119+ (a, s) <- liftIO $ runTemplate tpl p s l ()
120+ return a
120121
121122shouldRenderM :: Text -> Text -> LarcenyHspecM ()
122123shouldRenderM templateText output = do
@@ -325,19 +326,19 @@ spec = hspec $ do
325326 it " should allow you to write functions for fills" $ do
326327 let subs' =
327328 subs [(" desc" ,
328- Fill $ \ m _t _l -> return $ T. take (read $ T. unpack (m M. ! " length" ))
329- " A really long description"
330- <> " ..." )]
329+ Fill $ \ m _t _l s -> return ( T. take (read $ T. unpack (m M. ! " length" ))
330+ " A really long description"
331+ <> " ..." , s) )]
331332 hLarcenyState. lSubs .= subs'
332333 " <l:desc length=\" 10\" />" `shouldRenderM` " A really l..."
333334
334335 it " should allow you to use IO in fills" $ do
335336 let subs' =
336337 subs [(" desc" , Fill $
337- \ m _t _l -> do liftIO $ putStrLn " ***********\n Hello World\n ***********"
338- return $ T. take (read $ T. unpack (m M. ! " length" ))
339- " A really long description"
340- <> " ..." )]
338+ \ m _t _l s -> do putStrLn " ***********\n Hello World\n ***********"
339+ return ( T. take (read $ T. unpack (m M. ! " length" ))
340+ " A really long description"
341+ <> " ..." , s) )]
341342 hLarcenyState. lSubs .= subs'
342343 " <l:desc length=\" 10\" />" `shouldRenderM` " A really l..."
343344
@@ -383,7 +384,7 @@ spec = hspec $ do
383384 `shouldRenderM` " <p class=\" lots of space\" ></p>"
384385
385386 it " should know what the template path is" $ do
386- let fill = Fill $ \ _ (p, _) _ -> return (head p)
387+ let fill = Fill $ \ _ (p, _) _ s -> return (head p, s )
387388 hLarcenyState. lSubs .= subs [(" template" , fill)]
388389 " <p class=\" ${template}\" ></p>"
389390 `shouldRenderM` " <p class=\" default\" ></p>"
@@ -453,10 +454,9 @@ statefulTests =
453454 describe " statefulness" $ do
454455 it " a fill should be able to affect subsequent fills" $ do
455456 renderWith (M. fromList [([" default" ], parse " <x/><x/>" )])
456- (subs [(" x" , Fill $ \ _ _ _ ->
457- do modify ((+ 1 ) :: Int -> Int )
458- s <- get
459- return (T. pack (show s)))])
457+ (subs [(" x" , Fill $ \ _ _ _ s ->
458+ do let s' = s + 1
459+ return (T. pack (show s'), s'))])
460460 0
461461 [" default" ]
462462 `shouldReturn` Just " 12"
@@ -471,10 +471,9 @@ statefulTests =
471471 \<bind tag=\" test2\" >test2</bind>\
472472 \<x/><x/>"
473473 renderWith (M. fromList [([" default" ], parse tpl)])
474- (subs [(" x" , Fill $ \ _ _ _ ->
475- do modify ((+ 1 ) :: Int -> Int )
476- s <- get
477- return (T. pack (show s)))])
474+ (subs [(" x" , Fill $ \ _ _ _ s ->
475+ do let s' = s + 1
476+ return (T. pack (show s'), s'))])
478477 0
479478 [" default" ]
480479 `shouldReturn` Just " 12"
@@ -641,9 +640,9 @@ attrTests =
641640 it " should allow you use child elements" $ do
642641 let descTplFill =
643642 useAttrs (a" length" )
644- (\ n -> Fill $ \ _attrs (_pth, tpl) _l -> liftIO $ do
645- t' <- evalStateT ( runTemplate tpl [" default" ] mempty mempty ) ()
646- return $ T. take n t' <> " ..." )
643+ (\ n -> Fill $ \ _attrs (_pth, tpl) _l st -> liftIO $ do
644+ (t', st') <- runTemplate tpl [" default" ] mempty mempty st
645+ return ( T. take n t' <> " ..." , st') )
647646 hLarcenyState. lSubs .= subs [ (" adverb" , textFill " really" )
648647 , (" desc" , descTplFill)]
649648 " <l:desc length=\" 10\" >A <adverb /> long description</desc>"
@@ -681,8 +680,8 @@ attrTests =
681680 descFunc :: Int -> Maybe Text -> Fill ()
682681 descFunc n e = Fill $
683682 do let ending = fromMaybe " ..." e
684- \ _attrs (_pth, tpl) _l -> liftIO $ do
685- renderedText <- evalStateT ( runTemplate tpl [" default" ] mempty mempty ) ()
686- return $ T. take n renderedText <> ending
683+ \ _attrs (_pth, tpl) _l st -> liftIO $ do
684+ ( renderedText, st') <- runTemplate tpl [" default" ] mempty mempty st
685+ return ( T. take n renderedText <> ending, st')
687686
688687{-# ANN module ("HLint: ignore Redundant do" :: String) #-}
0 commit comments