packages feed

wai-digestive-functors (empty) → 0.1

raw patch · 5 files changed

+119/−0 lines, 5 filesdep +basedep +digestive-functorsdep +http-typessetup-changed

Dependencies added: base, digestive-functors, http-types, resourcet, text, wai, wai-extra, wai-util

Files

+ COPYING view
@@ -0,0 +1,13 @@+Copyright © 2013, Stephen Paul Weber <singpolyma.net>++Permission to use, copy, modify, and/or distribute this software for any+purpose with or without fee is hereby granted, provided that the above+copyright notice and this permission notice appear in all copies.++THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES+WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF+MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR+ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES+WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN+ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF+OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ Network/Wai/Digestive.hs view
@@ -0,0 +1,62 @@+-- | Helpers to bind 'digestive-functors' onto a 'wai' request+module Network.Wai.Digestive (queryFormEnv, bodyFormEnv, bodyFormEnv_, requestFormEnv, requestFormEnv_) where++import Control.Arrow (second)+import Text.Digestive (Env, FormInput(..))+import Network.HTTP.Types.QueryLike (QueryLike, toQuery, toQueryValue)+import Network.Wai (Request, queryString)+import Control.Monad.Trans.Resource (ResourceT)+import Network.Wai.Util (queryLookupAll)+import Network.Wai.Parse (parseRequestBody, BackEnd, File, fileContent, tempFileBackEnd)+import Data.Text (Text)+import qualified Data.Text as T++newtype FileQuery = FileQuery [File FilePath]++instance QueryLike FileQuery where+	toQuery (FileQuery files) =+		map (second (toQueryValue . fileContent)) files++-- Manual currying for performance+-- | Build an 'Text.Digestive.Types.Env' from a query+queryFormEnv :: (QueryLike q, Monad m) => q -> Env m+queryFormEnv qs = \pth ->+	return $ map TextInput $ queryLookupAll (pathToText pth) qs'+	where+	qs' = toQuery qs++-- | Build an 'Text.Digestive.Types.Env' from a request body+bodyFormEnv :: BackEnd FilePath -> Request -> Env (ResourceT IO)+bodyFormEnv backend req pth = do+	(query, files) <- parseRequestBody backend req+	queryFormEnv (toQuery query ++ toQuery (FileQuery files)) pth++-- | Build an 'Text.Digestive.Types.Env' from a request body+--+-- Uses a default temporary file 'Network.Wai.Parse.BackEnd'+bodyFormEnv_ :: Request -> Env (ResourceT IO)+bodyFormEnv_ = bodyFormEnv tempFileBackEnd++-- | Build an 'Text.Digestive.Types.Env' from request body and query string+requestFormEnv :: BackEnd FilePath -> Request -> Env (ResourceT IO)+requestFormEnv backend req pth = do+	(query, files) <- parseRequestBody backend req+	queryFormEnv (toQuery query ++ toQuery (FileQuery files) ++ queryString req) pth++-- | Build an 'Text.Digestive.Types.Env' from request body and query string+--+-- Uses a default temporary file 'Network.Wai.Parse.BackEnd'+requestFormEnv_ :: Request -> Env (ResourceT IO)+requestFormEnv_ = requestFormEnv tempFileBackEnd++-- | Format form paths just like PHP/Rails+pathToText :: [Text] -> Text+pathToText [] = T.empty+pathToText [p] = p+pathToText (p:ps) = T.concat (p : concatMap fragment ps)+	where+	fragment n = [+			T.singleton '[',+			n,+			T.singleton ']'+		]
+ README view
@@ -0,0 +1,2 @@+Allows forms build with 'digestive-functors' to easy get their data+out of wai requests.
+ Setup.hs view
@@ -0,0 +1,3 @@+import Distribution.Simple++main = defaultMain
+ wai-digestive-functors.cabal view
@@ -0,0 +1,39 @@+name:            wai-digestive-functors+version:         0.1+cabal-version:   >= 1.8+license:         OtherLicense+license-file:    COPYING+category:        Web+copyright:       © 2013 Stephen Paul Weber+author:          Stephen Paul Weber <singpolyma@singpolyma.net>+maintainer:      Stephen Paul Weber <singpolyma@singpolyma.net>+stability:       experimental+tested-with:     GHC == 7.6.2+synopsis:        Helpers to bind digestive-functors onto wai requests+homepage:        https://github.com/singpolyma/wai-digestive-functors+bug-reports:     https://github.com/singpolyma/wai-digestive-functors/issues+build-type:      Simple+description:+        Allows forms build with 'digestive-functors' to easy get their data+        out of wai requests.++extra-source-files:+        README++library+        exposed-modules:+                Network.Wai.Digestive++        build-depends:+                base == 4.*,+                wai,+                wai-extra,+                wai-util >= 0.6,+                resourcet,+                text,+                http-types,+                digestive-functors++source-repository head+        type:     git+        location: git://github.com/singpolyma/wai-digestive-functors.git