packages feed

Spock 0.4.4.0 → 0.4.4.1

raw patch · 3 files changed

+42/−2 lines, 3 files

Files

Spock.cabal view
@@ -1,5 +1,5 @@ name:                Spock-version:             0.4.4.0+version:             0.4.4.1 synopsis:            Another Haskell web toolkit based on scotty description:         This toolbox provides everything you need to get a quick start into web hacking with haskell: sessions, cookies, database helper, csrf-protection, global state and the power of scotty Homepage:            https://github.com/agrafix/Spock@@ -19,7 +19,8 @@                        Web.Spock.Monad,                        Web.Spock.Cookie,                        Web.Spock.Types,-                       Web.Spock.SafeActions+                       Web.Spock.SafeActions,+                       Web.Spock.Digestive   build-depends:       base >= 4 && < 5,                        scotty >= 0.6,                        wai >=2.0,
src/Web/Spock/Cookie.hs view
@@ -1,4 +1,5 @@ {-# LANGUAGE OverloadedStrings #-}+{-# LANGUAGE ConstraintKinds #-} module Web.Spock.Cookie where  import Web.Spock.Types
+ src/Web/Spock/Digestive.hs view
@@ -0,0 +1,38 @@+{-# LANGUAGE DoAndIfThenElse #-}+module Web.Spock.Digestive+    ( runForm )+where++import Web.Spock.Types++import Control.Applicative+import Network.HTTP.Types+import Network.Wai+import Network.Wai.Parse+import Text.Digestive.Form+import Text.Digestive.Types+import Text.Digestive.View+import Web.Scotty.Trans+import qualified Data.ByteString.Char8 as BS+import qualified Data.Text as T+import qualified Data.Text.Lazy as TL++-- | Run a digestive functors form+runForm :: T.Text -- ^ form name+        -> Form v (SpockAction conn sess st) a+        -> SpockAction conn sess st (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 :: Env (SpockAction conn sess st)+      localEnv path =+          do let name = TL.fromStrict $ fromPath $ path+                 applyParam f =+                     map (f . snd) . filter ((== name) . fst)+             vars <- (applyParam (TextInput . TL.toStrict)) <$> params+             sentFiles <- (applyParam (FileInput . BS.unpack . fileName)) <$> files+             return (vars ++ sentFiles)