diff --git a/lucid-colonnade/lucid-colonnade.cabal b/lucid-colonnade/lucid-colonnade.cabal index 21ecc44..8109ee1 100644 --- a/lucid-colonnade/lucid-colonnade.cabal +++ b/lucid-colonnade/lucid-colonnade.cabal @@ -21,6 +21,7 @@ library , colonnade >= 1.1.1 && < 1.3 , lucid >= 2.9 && < 3.0 , text >= 1.2 && < 1.3 + , vector >= 0.10 && < 0.13 default-language: Haskell2010 source-repository head diff --git a/lucid-colonnade/src/Lucid/Colonnade.hs b/lucid-colonnade/src/Lucid/Colonnade.hs index aa8abe2..a2c1804 100644 --- a/lucid-colonnade/src/Lucid/Colonnade.hs +++ b/lucid-colonnade/src/Lucid/Colonnade.hs @@ -40,13 +40,15 @@ import Data.String (IsString(..)) import Data.Maybe (listToMaybe) import Data.Char (isSpace) import Control.Applicative (liftA2) -import Lucid +import Lucid hiding (for_) import qualified Colonnade as Col import qualified Data.List as List import qualified Colonnade.Encode as E import qualified Data.Text as Text import qualified Data.Text.Lazy as LText import qualified Data.Text.Lazy.Builder as TBuilder +import qualified Data.Vector as V +import qualified Data.Text as T -- $build -- @@ -264,4 +266,28 @@ htmlFromCell f (Cell attr content) = f attr content -- situation, it is necessary to introduce 'Cell', which includes -- the possibility of attributes on the parent node. +sectioned :: + (Foldable f, E.Headedness h, Foldable g, Monoid c) + => [Attribute] -- ^ @\@ tag attributes + -> Maybe ([Attribute], [Attribute]) + -- ^ Attributes of @\@ and its @\@, pass 'Nothing' to omit @\@ + -> [Attribute] -- ^ @\@ tag attributes + -> (a -> [Attribute]) -- ^ @\@ tag attributes for data rows + -> (b -> Cell c) -- ^ Section divider encoding strategy + -> Colonnade h a (Cell c) -- ^ Data encoding strategy + -> f (b, g a) -- ^ Collection of data + -> Html () +sectioned tableAttrs mheadAttrs bodyAttrs trAttrs dividerContent colonnade@(E.Colonnade v) collection = do + pure () + let vlen = V.length v + table_ tableAttrs $ do + for_ mheadAttrs $ \(headAttrs,headTrAttrs) -> + thead_ headAttrs . tr_ headTrAttrs $ + E.headerMonadicGeneral_ colonnade (htmlFromCell th_) + tbody_ bodyAttrs $ forM_ collection $ \(b,as) -> do + let Cell attrs contents = dividerContent b + tr_ [] $ do + td_ ((colspan_ $ T.pack (show vlen)): attrs) contents + flip foldlMapM' as $ \a -> do + tr_ (trAttrs a) $ E.rowMonadic colonnade (htmlFromCell td_) a diff --git a/yesod-colonnade/yesod-colonnade.cabal b/yesod-colonnade/yesod-colonnade.cabal index b64d6e9..dfd7b0f 100644 --- a/yesod-colonnade/yesod-colonnade.cabal +++ b/yesod-colonnade/yesod-colonnade.cabal @@ -17,7 +17,7 @@ library exposed-modules: Yesod.Colonnade build-depends: - base >= 4.9.1.0 && < 4.12 + base >= 4.9.1.0 && < 4.13 , colonnade >= 1.2 && < 1.3 , yesod-core >= 1.6 && < 1.7 , conduit >= 1.3 && < 1.4