digestive-functors-happstack 0.1.1.5 → 0.3.0.0
raw patch · 3 files changed
+45/−81 lines, 3 filesdep −utf8-stringdep ~digestive-functorsdep ~happstack-serverPVP ok
version bump matches the API change (PVP)
Dependencies removed: utf8-string
Dependency ranges changed: digestive-functors, happstack-server
API changes (from Hackage documentation)
- Text.Digestive.Forms.Happstack: eitherHappstackForm :: (HasRqData m, MonadPlus m, Alternative m, ServerMonad m) => HappstackForm m e v a -> String -> m (Either v a)
- Text.Digestive.Forms.Happstack: happstackEnvironment :: (HasRqData m, MonadPlus m, Alternative m) => Environment m [Input]
- Text.Digestive.Forms.Happstack: instance FormInput [Input] (String, FilePath)
- Text.Digestive.Forms.Happstack: type HappstackForm m = Form m [Input]
+ Text.Digestive.Happstack: runForm :: (HasRqData m, Monad m, ServerMonad m) => Text -> Form v m a -> m (View v, Maybe a)
Files
- digestive-functors-happstack.cabal +9/−11
- src/Text/Digestive/Forms/Happstack.hs +0/−70
- src/Text/Digestive/Happstack.hs +36/−0
digestive-functors-happstack.cabal view
@@ -1,14 +1,12 @@ Name: digestive-functors-happstack-Version: 0.1.1.5+Version: 0.3.0.0 Synopsis: Happstack backend for the digestive-functors library-Description: This is a happstack backend for the digestive-functors- library.-+Description: Happstack backend for the digestive-functors library Homepage: http://github.com/jaspervdj/digestive-functors License: BSD3 License-file: LICENSE-Author: Jasper Van der Jeugt-Maintainer: jaspervdj@gmail.com+Author: Jasper Van der Jeugt <m@jaspervdj.be>+Maintainer: Jasper Van der Jeugt <m@jaspervdj.be> Category: Web Build-type: Simple Cabal-version: >= 1.6@@ -16,12 +14,12 @@ Library Hs-source-dirs: src- Exposed-modules: Text.Digestive.Forms.Happstack+ GHC-options: -Wall -fwarn-tabs+ Exposed-modules: Text.Digestive.Happstack Build-depends: base >= 4 && < 5, bytestring >= 0.9 && < 0.10,- digestive-functors >= 0.1 && < 0.3,- happstack-server >= 6.0 && < 7.1,- text >= 0.11 && < 1.0,- utf8-string >= 0.3 && < 0.4+ digestive-functors >= 0.3 && < 0.4,+ happstack-server >= 6.0 && < 6.7,+ text >= 0.11 && < 1.0
− src/Text/Digestive/Forms/Happstack.hs
@@ -1,70 +0,0 @@--- | Module providing a happstack backend for the digestive-functors library----{-# LANGUAGE FlexibleInstances, MultiParamTypeClasses #-}-{-# OPTIONS_GHC -fno-warn-orphans #-}-module Text.Digestive.Forms.Happstack- ( HappstackForm- , happstackEnvironment- , eitherHappstackForm- ) where--import Control.Monad (MonadPlus, liftM)-import Control.Applicative (Alternative, optional)-import Data.ByteString.Lazy.UTF8 as LB (toString)-import Data.Either-import Data.Text.Lazy as Text (toStrict)-import Data.Text.Lazy.Encoding as Text (decodeUtf8)-import Happstack.Server ( Input (..), HasRqData (..), lookInputs- , Method (..), ServerMonad (..), rqMethod- )--import Text.Digestive.Forms (FormInput (..))-import Text.Digestive.Types (Form (..), Environment (..), viewForm, eitherForm)--instance FormInput [Input] (String, FilePath) where- getInputStrings inps =- map LB.toString $ rights $ map inputValue inps-- getInputTexts inps =- map (Text.toStrict . Text.decodeUtf8) $ rights $ map inputValue inps-- getInputFile inps =- case inps of- (inp:_) ->- case inputValue inp of- (Left fp) ->- do fn <- inputFilename inp- return (fn, fp)- _ -> Nothing- _ -> Nothing---- | Simplification of the `Form` type, instantiated to Happstack----type HappstackForm m = Form m [Input]---- | Environment that will fetch input from the parameters parsed by Happstack----happstackEnvironment :: (HasRqData m, MonadPlus m, Alternative m)- => Environment m [Input]-happstackEnvironment = Environment $ fmap toMaybe . lookInputs . show- where- toMaybe :: [a] -> Maybe [a]- toMaybe [] = Nothing- toMaybe l = Just l---- | Run a happstack form------ * When we are responding to a GET request, you will simply receive the form--- as a view------ * When we are responding to another request method, the form data will be--- used. When errors occur, you will receive the form as a view, otherwise,--- you will get the actual result----eitherHappstackForm :: (HasRqData m, MonadPlus m, Alternative m, ServerMonad m)- => HappstackForm m e v a -- ^ Form- -> String -- ^ Form name- -> m (Either v a) -- ^ Result-eitherHappstackForm form name = askRq >>= \rq ->- case rqMethod rq of GET -> liftM Left $ viewForm form name- _ -> eitherForm form name happstackEnvironment
+ src/Text/Digestive/Happstack.hs view
@@ -0,0 +1,36 @@+-- | Module providing a happstack backend for the digestive-functors library+module Text.Digestive.Happstack+ ( runForm+ ) where++import Data.Text (Text)+import qualified Data.Text as T+import qualified Data.Text.Lazy as TL+import qualified Data.Text.Lazy.Encoding as TL+import qualified Happstack.Server as Happstack++import Text.Digestive.Form+import Text.Digestive.Types+import Text.Digestive.View++happstackEnv :: (Happstack.HasRqData m, Monad m) => Env m+happstackEnv path = do+ inputs <- Happstack.lookInputs $ T.unpack $ fromPath path+ return $ map toFormInput inputs+ where+ toFormInput input = case Happstack.inputValue input of+ Left filePath -> FileInput filePath+ Right bs -> TextInput $ TL.toStrict $ TL.decodeUtf8 bs++-- | Runs a form with the HTTP input provided by Happstack.+--+-- Automatically picks between 'getForm' and 'postForm' based on the request+-- method.+runForm :: (Happstack.HasRqData m, Monad m, Happstack.ServerMonad m)+ => Text -- ^ Name for the form+ -> Form v m a -- ^ Form to run+ -> m (View v, Maybe a) -- ^ Result+runForm name form = Happstack.askRq >>= \rq ->+ case Happstack.rqMethod rq of+ Happstack.GET -> return (getForm name form, Nothing)+ _ -> postForm name form happstackEnv