packages feed

yesod-colonnade 1.2.0 → 1.3.0

raw patch · 2 files changed

+52/−69 lines, 2 filesdep +conduitdep +conduit-extradep +yesod-elementsdep ~basedep ~yesod-corePVP ok

version bump matches the API change (PVP)

Dependencies added: conduit, conduit-extra, yesod-elements

Dependency ranges changed: base, yesod-core

API changes (from Hackage documentation)

+ Yesod.Colonnade: instance GHC.Base.Semigroup (Yesod.Colonnade.Cell site)
- Yesod.Colonnade: Cell :: !Attribute -> !(WidgetT site IO ()) -> Cell site
+ Yesod.Colonnade: Cell :: [Attribute] -> !(WidgetFor site ()) -> Cell site
- Yesod.Colonnade: [cellAttrs] :: Cell site -> !Attribute
+ Yesod.Colonnade: [cellAttrs] :: Cell site -> [Attribute]
- Yesod.Colonnade: [cellContents] :: Cell site -> !(WidgetT site IO ())
+ Yesod.Colonnade: [cellContents] :: Cell site -> !(WidgetFor site ())
- Yesod.Colonnade: anchorCell :: (a -> Route site) -> (a -> WidgetT site IO ()) -> a -> Cell site
+ Yesod.Colonnade: anchorCell :: (a -> Route site) -> (a -> WidgetFor site ()) -> a -> Cell site
- Yesod.Colonnade: anchorWidget :: (a -> Route site) -> (a -> WidgetT site IO ()) -> a -> WidgetT site IO ()
+ Yesod.Colonnade: anchorWidget :: (a -> Route site) -> (a -> WidgetFor site ()) -> a -> WidgetFor site ()
- Yesod.Colonnade: cell :: WidgetT site IO () -> Cell site
+ Yesod.Colonnade: cell :: WidgetFor site () -> Cell site
- Yesod.Colonnade: encodeCellTable :: (Foldable f, Headedness h) => Attribute -> Colonnade h a (Cell site) -> f a -> WidgetT site IO ()
+ Yesod.Colonnade: encodeCellTable :: (Foldable f, Headedness h) => [Attribute] -> Colonnade h a (Cell site) -> f a -> WidgetFor site ()
- Yesod.Colonnade: encodeDefinitionTable :: Attribute -> Colonnade Headed a (Cell site) -> a -> WidgetT site IO ()
+ Yesod.Colonnade: encodeDefinitionTable :: [Attribute] -> Colonnade Headed a (Cell site) -> a -> WidgetFor site ()
- Yesod.Colonnade: encodeListItems :: (WidgetT site IO () -> WidgetT site IO ()) -> (WidgetT site IO () -> WidgetT site IO () -> WidgetT site IO ()) -> Colonnade Headed a (Cell site) -> a -> WidgetT site IO ()
+ Yesod.Colonnade: encodeListItems :: (WidgetFor site () -> WidgetFor site ()) -> (WidgetFor site () -> WidgetFor site () -> WidgetFor site ()) -> Colonnade Headed a (Cell site) -> a -> WidgetFor site ()
- Yesod.Colonnade: encodeWidgetTable :: (Foldable f, Headedness h) => Attribute -> Colonnade h a (WidgetT site IO ()) -> f a -> WidgetT site IO ()
+ Yesod.Colonnade: encodeWidgetTable :: (Foldable f, Headedness h) => [Attribute] -> Colonnade h a (WidgetFor site ()) -> f a -> WidgetFor site ()

Files

src/Yesod/Colonnade.hs view
@@ -22,14 +22,16 @@   ) 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) import Data.Foldable+import Yesod.Elements (table_,thead_,tbody_,tr_,td_,th_,ul_,li_,a_) import qualified Text.Blaze.Html5.Attributes as HA import qualified Text.Blaze.Html5 as H import qualified Colonnade.Encode as E@@ -40,19 +42,21 @@ -- | The attributes that will be applied to a @<td>@ and --   the HTML content that will go inside it. data Cell site = Cell-  { cellAttrs :: !Attribute-  , cellContents :: !(WidgetT site IO ())+  { cellAttrs :: [Attribute]+  , cellContents :: !(WidgetFor site ())   }  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+cell :: WidgetFor site () -> Cell site cell = Cell mempty  -- | Create a 'Cell' from a 'String'@@ -71,7 +75,7 @@ --   it in an @\<a\>@. anchorCell ::       (a -> Route site) -- ^ Route that will go in @href@ attribute-  -> (a -> WidgetT site IO ()) -- ^ Content wrapped by @<a>@ tag+  -> (a -> WidgetFor site ()) -- ^ Content wrapped by @<a>@ tag   -> a -- ^ Value   -> Cell site anchorCell getRoute getContent = cell . anchorWidget getRoute getContent@@ -80,26 +84,26 @@ --   it in an @\<a\>@. anchorWidget ::       (a -> Route site) -- ^ Route that will go in @href@ attribute-  -> (a -> WidgetT site IO ()) -- ^ Content wrapped by @<a>@ tag+  -> (a -> WidgetFor site ()) -- ^ Content wrapped by @<a>@ tag   -> a -- ^ Value-  -> WidgetT site IO ()+  -> WidgetFor site () anchorWidget getRoute getContent a = do   urlRender <- getUrlRender-  a_ (HA.href (toValue (urlRender (getRoute a)))) (getContent a)+  a_ [HA.href (toValue (urlRender (getRoute a)))] (getContent a)  -- | This determines the attributes that are added --   to the individual @li@s by concatenating the header\'s --   attributes with the data\'s attributes.  encodeListItems :: -     (WidgetT site IO () -> WidgetT site IO ())+     (WidgetFor site () -> WidgetFor site ())      -- ^ Wrapper for items, often @ul@-  -> (WidgetT site IO () -> WidgetT site IO () -> WidgetT site IO ())+  -> (WidgetFor site () -> WidgetFor site () -> WidgetFor site ())      -- ^ Combines header with data   -> Colonnade Headed a (Cell site)      -- ^ How to encode data as a row   -> a      -- ^ The value to display-  -> WidgetT site IO ()+  -> WidgetFor site () encodeListItems ulWrap combine enc =   ulWrap . E.bothMonadic_ enc     (\(Cell ha hc) (Cell ba bc) ->@@ -110,16 +114,16 @@ --   first column and the data displayed in the second column. Note --   that the generated HTML table does not have a @thead@. encodeDefinitionTable ::-     Attribute+     [Attribute]      -- ^ Attributes of @table@ element.   -> Colonnade Headed a (Cell site)      -- ^ How to encode data as a row   -> a      -- ^ The value to display-  -> WidgetT site IO ()-encodeDefinitionTable attrs enc a = table_ attrs $ tbody_ mempty $ +  -> WidgetFor site ()+encodeDefinitionTable attrs enc a = table_ attrs $ tbody_ [] $    E.bothMonadic_ enc-    (\theKey theValue -> tr_ mempty $ do+    (\theKey theValue -> tr_ [] $ do       widgetFromCell td_ theKey       widgetFromCell td_ theValue     ) a@@ -130,19 +134,19 @@ -- --   > encodeCellTable (HA.class_ "table table-striped") ... encodeCellTable :: (Foldable f, E.Headedness h)-  => Attribute -- ^ Attributes of @table@ element+  => [Attribute] -- ^ Attributes of @table@ element   -> Colonnade h a (Cell site) -- ^ How to encode data as a row   -> f a -- ^ Rows of data-  -> WidgetT site IO ()+  -> WidgetFor site () encodeCellTable = encodeTable   (E.headednessPure mempty) mempty (const mempty) widgetFromCell   -- | Encode an html table. encodeWidgetTable :: (Foldable f, E.Headedness h)-  => Attribute -- ^ Attributes of @\<table\>@ element-  -> Colonnade h a (WidgetT site IO ()) -- ^ How to encode data as columns+  => [Attribute] -- ^ Attributes of @\<table\>@ element+  -> Colonnade h a (WidgetFor site ()) -- ^ How to encode data as columns   -> f a -- ^ Rows of data-  -> WidgetT site IO ()+  -> WidgetFor site () encodeWidgetTable = encodeTable   (E.headednessPure mempty) mempty (const mempty) ($ mempty)  @@ -151,14 +155,14 @@ --   used to add attributes to the generated @\<tr\>@ elements. encodeTable ::      (Foldable f, E.Headedness h)-  => h Attribute -- ^ Attributes of @\<thead\>@, pass 'Nothing' to omit @\<thead\>@-  -> Attribute -- ^ Attributes of @\<tbody\>@ element-  -> (a -> Attribute) -- ^ Attributes of each @\<tr\>@ element-  -> ((Attribute -> WidgetT site IO () -> WidgetT site IO ()) -> c -> WidgetT site IO ()) -- ^ Wrap content and convert to 'Html'-  -> Attribute -- ^ Attributes of @\<table\>@ element+  => h [Attribute] -- ^ Attributes of @\<thead\>@+  -> [Attribute] -- ^ Attributes of @\<tbody\>@ element+  -> (a -> [Attribute]) -- ^ Attributes of each @\<tr\>@ element+  -> (([Attribute] -> WidgetFor site () -> WidgetFor site ()) -> c -> WidgetFor site ()) -- ^ Wrap content and convert to 'Html'+  -> [Attribute] -- ^ Attributes of @\<table\>@ element   -> Colonnade h a c -- ^ How to encode data as a row   -> f a -- ^ Collection of data-  -> WidgetT site IO ()+  -> WidgetFor site () encodeTable theadAttrs tbodyAttrs trAttrs wrapContent tableAttrs colonnade xs =   table_ tableAttrs $ do     for_ E.headednessExtract $ \unhead ->@@ -169,33 +173,9 @@         tr_ (trAttrs x) (E.rowMonadic_ colonnade (wrapContent td_) x)  widgetFromCell ::-  (Attribute -> WidgetT site IO () -> WidgetT site IO ())+     ([Attribute] -> WidgetFor site () -> WidgetFor site ())   -> Cell site-  -> WidgetT site IO ()+  -> WidgetFor site () widgetFromCell f (Cell attrs contents) =   f attrs contents--tr_,tbody_,thead_,table_,td_,th_,ul_,li_,a_ ::-  Attribute -> WidgetT site IO () -> WidgetT site IO ()--table_ = liftParent H.table-thead_ = liftParent H.thead-tbody_ = liftParent H.tbody-tr_ = liftParent H.tr-td_ = liftParent H.td-th_ = liftParent H.th-ul_ = liftParent H.ul-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 })--- 
yesod-colonnade.cabal view
@@ -1,30 +1,33 @@-name:                yesod-colonnade-version:             1.2.0-synopsis:            Helper functions for using yesod with colonnade-description:         Yesod and colonnade-homepage:            https://github.com/andrewthad/colonnade#readme-license:             BSD3-license-file:        LICENSE-author:              Andrew Martin-maintainer:          andrew.thaddeus@gmail.com-copyright:           2016 Andrew Martin-category:            web-build-type:          Simple-cabal-version:       >=1.10+cabal-version: 2.0+name: yesod-colonnade+version: 1.3.0+synopsis: Helper functions for using yesod with colonnade+description: Yesod and colonnade+homepage: https://github.com/andrewthad/colonnade#readme+license: BSD3+license-file: LICENSE+author: Andrew Martin+maintainer: andrew.thaddeus@gmail.com+copyright: 2018 Andrew Martin+category: web+build-type: Simple  library   hs-source-dirs: src   exposed-modules:     Yesod.Colonnade   build-depends:-      base >= 4.7 && < 5+      base >= 4.9 && < 4.12     , colonnade >= 1.2 && < 1.3-    , yesod-core >= 1.4 && < 1.5+    , 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+    , yesod-elements >= 1.1 && < 1.2   default-language: Haskell2010  source-repository head-  type:     git+  type: git   location: https://github.com/andrewthad/colonnade