From f6020efa0026ab043e3f71cee81bfb22865f380c Mon Sep 17 00:00:00 2001 From: Michael Snoyman Date: Tue, 3 Jul 2018 21:47:54 +0300 Subject: [PATCH] Compatibility with yesod-core 1.6 Caveat: I'm not sure that the Semigroup instance is compatible with GHC before 8.4. --- stack.yaml | 2 +- yesod-colonnade/src/Yesod/Colonnade.hs | 21 +++++++++++++-------- yesod-colonnade/yesod-colonnade.cabal | 8 ++++---- 3 files changed, 18 insertions(+), 13 deletions(-) diff --git a/stack.yaml b/stack.yaml index e026e1c..f3d2d20 100644 --- a/stack.yaml +++ b/stack.yaml @@ -4,7 +4,7 @@ packages: - 'blaze-colonnade' - 'lucid-colonnade' - 'siphon' -# - 'yesod-colonnade' +- 'yesod-colonnade' # - 'geolite-csv' # Dependency packages to be pulled from upstream that are not in the resolver # (e.g., acme-missiles-0.3) diff --git a/yesod-colonnade/src/Yesod/Colonnade.hs b/yesod-colonnade/src/Yesod/Colonnade.hs index 4b7ea4e..75f43b7 100644 --- a/yesod-colonnade/src/Yesod/Colonnade.hs +++ b/yesod-colonnade/src/Yesod/Colonnade.hs @@ -22,10 +22,11 @@ module Yesod.Colonnade ) where import Yesod.Core -import Yesod.Core.Types (Body(..),GWData(..),WidgetT(..)) +import Yesod.Core.Types (Body(..),GWData(..),WidgetFor(..),wdRef) import Colonnade (Colonnade,Headed,Headless) import Data.Text (Text) import Control.Monad +import Data.IORef (modifyIORef') import Data.Monoid import Data.String (IsString(..)) import Text.Blaze (Attribute,toValue) @@ -47,9 +48,11 @@ data Cell site = Cell instance IsString (Cell site) where fromString = stringCell +instance Semigroup (Cell site) where + Cell a1 c1 <> Cell a2 c2 = Cell (mappend a1 a2) (mappend c1 c2) instance Monoid (Cell site) where mempty = Cell mempty mempty - mappend (Cell a1 c1) (Cell a2 c2) = Cell (mappend a1 a2) (mappend c1 c2) + mappend = (<>) -- | Create a 'Cell' from a 'Widget' cell :: WidgetT site IO () -> Cell site @@ -189,12 +192,14 @@ li_ = liftParent H.li a_ = liftParent H.a liftParent :: (Html -> Html) -> Attribute -> WidgetT site IO a -> WidgetT site IO a -liftParent el attrs (WidgetT f) = WidgetT $ \hdata -> do - (a,gwd) <- f hdata - let Body bodyFunc = gwdBody gwd - newBodyFunc render = - el H.! attrs $ (bodyFunc render) - return (a,gwd { gwdBody = Body newBodyFunc }) +liftParent el attrs (WidgetFor f) = WidgetFor $ \hdata -> do + a <- f hdata + modifyIORef' (wdRef hdata) $ \gwd -> + let Body bodyFunc = gwdBody gwd + newBodyFunc render = + el H.! attrs $ (bodyFunc render) + in gwd { gwdBody = Body newBodyFunc } + return a diff --git a/yesod-colonnade/yesod-colonnade.cabal b/yesod-colonnade/yesod-colonnade.cabal index ed2030d..bcab0c7 100644 --- a/yesod-colonnade/yesod-colonnade.cabal +++ b/yesod-colonnade/yesod-colonnade.cabal @@ -17,11 +17,11 @@ library exposed-modules: Yesod.Colonnade build-depends: - base >= 4.9 && < 4.11 + base >= 4.9 && < 4.12 , colonnade >= 1.2 && < 1.3 - , yesod-core >= 1.4 && < 1.5 - , conduit >= 1.2 && < 1.3 - , conduit-extra >= 1.2 && < 1.3 + , yesod-core >= 1.6 && < 1.7 + , conduit >= 1.3 && < 1.4 + , conduit-extra >= 1.3 && < 1.4 , text >= 1.0 && < 1.3 , blaze-markup >= 0.7 && < 0.9 , blaze-html >= 0.8 && < 0.10