packages feed

Spock-digestive (empty) → 0.1.0.0

raw patch · 4 files changed

+85/−0 lines, 4 filesdep +Spockdep +basedep +digestive-functorssetup-changed

Dependencies added: Spock, base, digestive-functors, http-types, mtl, text, unordered-containers, wai

Files

+ LICENSE view
@@ -0,0 +1,20 @@+Copyright (c) 2014 Alexander Thiemann <mail@athiemann.net>++Permission is hereby granted, free of charge, to any person obtaining+a copy of this software and associated documentation files (the+"Software"), to deal in the Software without restriction, including+without limitation the rights to use, copy, modify, merge, publish,+distribute, sublicense, and/or sell copies of the Software, and to+permit persons to whom the Software is furnished to do so, subject to+the following conditions:++The above copyright notice and this permission notice shall be included+in all copies or substantial portions of the Software.++THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.+IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY+CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,+TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE+SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ Spock-digestive.cabal view
@@ -0,0 +1,27 @@+name:                Spock-digestive+version:             0.1.0.0+synopsis:            Digestive functors support for Spock+description:         Run forms defined using digestive functors with Spock+homepage:            https://github.com/agrafix/Spock-digestive+license:             MIT+license-file:        LICENSE+author:              Alexander Thiemann <mail@athiemann.net>+maintainer:          mail@athiemann.net+copyright:           (c) 2014 Alexander Thiemann <mail@athiemann.net>+category:            Web+build-type:          Simple+cabal-version:       >=1.10++library+  exposed-modules:     Web.Spock.Digestive+  build-depends:+                       Spock >=0.7.6,+                       base >=4.6 && <5,+                       digestive-functors >=0.7,+                       http-types >=0.8,+                       mtl >=2.0,+                       text >=0.11.3.1,+                       unordered-containers >=0.2,+                       wai >=3.0+  hs-source-dirs:      src+  default-language:    Haskell2010
+ src/Web/Spock/Digestive.hs view
@@ -0,0 +1,36 @@+{-# LANGUAGE DoAndIfThenElse #-}+module Web.Spock.Digestive+    ( runForm )+where++import Web.Spock.Shared++import Control.Applicative+import Control.Monad.Trans+import Network.HTTP.Types+import Network.Wai+import Text.Digestive.Form+import Text.Digestive.Types+import Text.Digestive.View+import qualified Data.HashMap.Strict as HM+import qualified Data.Text as T++-- | Run a digestive functors form+runForm :: (Functor m, MonadIO m)+        => T.Text -- ^ form name+        -> Form v (ActionT m) a+        -> ActionT m (View v, Maybe a)+runForm formName form =+    do httpMethod <- requestMethod <$> request+       if httpMethod == methodGet+       then do f <- getForm formName form+               return (f, Nothing)+       else postForm formName form (const $ return localEnv)+    where+      localEnv path =+          do let name = fromPath $ path+                 applyParam f =+                     map (f . snd) . filter ((== name) . fst)+             vars <- (applyParam (TextInput)) <$> params+             sentFiles <- (applyParam (FileInput . T.unpack . uf_name) . HM.toList) <$> files+             return (vars ++ sentFiles)