packages feed

reflex-dom-colonnade (empty) → 0.1

raw patch · 4 files changed

+113/−0 lines, 4 filesdep +basedep +colonnadedep +containerssetup-changed

Dependencies added: base, colonnade, containers, contravariant, reflex, reflex-dom, vector

Files

+ LICENSE view
@@ -0,0 +1,30 @@+Copyright Andrew Martin (c) 2016++All rights reserved.++Redistribution and use in source and binary forms, with or without+modification, are permitted provided that the following conditions are met:++    * Redistributions of source code must retain the above copyright+      notice, this list of conditions and the following disclaimer.++    * Redistributions in binary form must reproduce the above+      copyright notice, this list of conditions and the following+      disclaimer in the documentation and/or other materials provided+      with the distribution.++    * Neither the name of Andrew Martin nor the names of other+      contributors may be used to endorse or promote products derived+      from this software without specific prior written permission.++THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ reflex-dom-colonnade.cabal view
@@ -0,0 +1,31 @@+name:                reflex-dom-colonnade+version:             0.1+synopsis:            Use colonnade with reflex-dom+description:         Please see README.md+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++library+  hs-source-dirs:      src+  exposed-modules:+    Reflex.Dom.Colonnade+  build-depends:+      base >= 4.7 && < 5+    , colonnade+    , contravariant+    , vector+    , reflex+    , reflex-dom+    , containers+  default-language:    Haskell2010++source-repository head+  type:     git+  location: https://github.com/andrewthad/colonnade
+ src/Reflex/Dom/Colonnade.hs view
@@ -0,0 +1,50 @@+module Reflex.Dom.Colonnade where++import Colonnade.Types+import Control.Monad+import Reflex (Dynamic)+import Reflex.Dynamic (mapDyn)+import Reflex.Dom (MonadWidget)+import Reflex.Dom.Widget.Basic+import Data.Map (Map)+import qualified Data.Map as Map++cell :: m () -> Cell m+cell = Cell Map.empty++data Cell m = Cell+  { cellAttrs :: Map String String+  , cellContents :: m ()+  }++basic :: (MonadWidget t m, Foldable f)+      => Map String String -- ^ Table element attributes+      -> f a -- ^ Values+      -> Encoding Headed (Cell m) a -- ^ Encoding of a value into cells+      -> m ()+basic tableAttrs as (Encoding v) = do+  elAttr "table" tableAttrs $ do+    el "thead" $ forM_ v $ \(Headed (Cell attrs contents),_) ->+      elAttr "th" attrs contents+    el "tbody" $ forM_ as $ \a -> do+      el "tr" $ forM_ v $ \(_,encode) -> do+        let Cell attrs contents = encode a+        elAttr "td" attrs contents++dynamic :: (MonadWidget t m, Foldable f)+        => Map String String -- ^ Table element attributes+        -> f (Dynamic t a) -- ^ Dynamic values+        -> Encoding Headed (Cell m) a -- ^ Encoding of a value into cells+        -> m ()+dynamic tableAttrs as (Encoding v) = do+  elAttr "table" tableAttrs $ do+    el "thead" $ forM_ v $ \(Headed (Cell attrs contents),_) ->+      elAttr "th" attrs contents+    el "tbody" $ forM_ as $ \a -> do+      el "tr" $ forM_ v $ \(_,encode) -> do+        dynPair <- mapDyn encode a+        dynAttrs <- mapDyn cellAttrs dynPair+        dynContent <- mapDyn cellContents dynPair+        _ <- elDynAttr "td" dynAttrs $ dyn dynContent+        return ()+