lucid2 0.0.20220526 → 0.0.20221012
raw patch · 4 files changed
+29/−6 lines, 4 filesdep ~base
Dependency ranges changed: base
Files
- CHANGELOG.md +4/−0
- lucid2.cabal +2/−2
- src/Lucid/Base.hs +13/−4
- test/Main.hs +10/−0
CHANGELOG.md view
@@ -1,3 +1,7 @@+## 0.0.20221012++* Fix `commuteHtmlT` in favor of newly added `commuteHtmlT2`+ ## 0.0.20220526 This release adds some extra functions for running different monad
lucid2.cabal view
@@ -1,5 +1,5 @@ name: lucid2-version: 0.0.20220526+version: 0.0.20221012 synopsis: Clear to write, read and edit DSL for HTML description: Clear to write, read and edit DSL for HTML.@@ -33,7 +33,7 @@ Lucid.Html5 -- GHC boot libraries- build-depends: base >= 4.8 && < 4.17+ build-depends: base >= 4.8 && < 4.18 , bytestring >= 0.10.12.0 , containers >= 0.6.5.1 , transformers >= 0.5.6.2
src/Lucid/Base.hs view
@@ -23,7 +23,7 @@ ,evalHtmlT ,runHtmlT ,generalizeHtmlT- ,commuteHtmlT+ ,commuteHtmlT2 ,hoistHtmlT -- * Combinators ,makeElement@@ -41,6 +41,7 @@ -- * Deprecated ,relaxHtmlT+ ,commuteHtmlT ) where @@ -337,12 +338,12 @@ -- exampleHtml' = evalState (commuteHtmlT exampleHtml) 1 -- @ ---commuteHtmlT :: (Monad m, Monad n)+commuteHtmlT2 :: (Monad m, Monad n) => HtmlT m a -- ^ unpurely generated HTML -> m (HtmlT n a) -- ^ Commuted monads. /Note:/ @n@ can be 'Identity'-commuteHtmlT h = do+commuteHtmlT2 h = do (builder, a) <- runHtmlT h- return . HtmlT $ put builder >> return a+ return . HtmlT $ modify' (<> builder) >> return a -- | Evaluate the HTML to its return value. Analogous to @evalState@. --@@ -453,3 +454,11 @@ relaxHtmlT :: Monad m => HtmlT Identity a -> HtmlT m a relaxHtmlT = undefined {-# DEPRECATED relaxHtmlT "DO NOT USE. This was exported accidentally and throws an exception." #-}++commuteHtmlT :: (Monad m, Monad n)+ => HtmlT m a -- ^ unpurely generated HTML+ -> m (HtmlT n a) -- ^ Commuted monads. /Note:/ @n@ can be 'Identity'+commuteHtmlT h = do+ (builder, a) <- runHtmlT h+ return . HtmlT $ put builder >> return a+{-# DEPRECATED commuteHtmlT "This has incorrect behavior and will lose HTML output. See commuteHtmlT2." #-}
test/Main.hs view
@@ -30,6 +30,7 @@ describe "attributes" testAttributes describe "special-elements" testSpecials describe "self-closing" testSelfClosing+ describe "commute" testCommute (==?*) :: (Eq a, Show a) => a -> [a] -> Assertion x ==?* xs | x `elem` xs = return ()@@ -154,3 +155,12 @@ it "input" (renderText (input_ [type_ "text"]) `shouldBe` "<input type=\"text\">")++testCommute :: Spec+testCommute = do+ it "commutes" $ do+ let stateAction :: HtmlT (Control.Monad.State.Strict.State [Integer]) ()+ stateAction = div_ [class_ "inside"] $ pure ()+ (fragment, _s) = runState (commuteHtmlT2 stateAction) [0]+ renderText (div_ [class_ "outside"] fragment) `shouldBe`+ "<div class=\"outside\"><div class=\"inside\"></div></div>"