packages feed

digestive-functors-happstack 0.0.2.1 → 0.1.0.0

raw patch · 2 files changed

+25/−21 lines, 2 filesdep ~digestive-functorsPVP ok

version bump matches the API change (PVP)

Dependency ranges changed: digestive-functors

API changes (from Hackage documentation)

- Text.Digestive.Forms.Happstack: instance FormInput Input (String, FilePath)
+ Text.Digestive.Forms.Happstack: instance FormInput [Input] (String, FilePath)
- Text.Digestive.Forms.Happstack: happstackEnvironment :: (HasRqData m, MonadPlus m, Alternative m) => Environment m Input
+ Text.Digestive.Forms.Happstack: happstackEnvironment :: (HasRqData m, MonadPlus m, Alternative m) => Environment m [Input]
- Text.Digestive.Forms.Happstack: type HappstackForm m e v a = Form m Input e v a
+ Text.Digestive.Forms.Happstack: type HappstackForm m e v a = Form m [Input] e v a

Files

digestive-functors-happstack.cabal view
@@ -1,5 +1,5 @@ Name:                digestive-functors-happstack-Version:             0.0.2.1+Version:             0.1.0.0 Synopsis:            Happstack backend for the digestive-functors library Description:         This is a happstack backend for the digestive-functors     library.@@ -18,7 +18,7 @@   Hs-source-dirs:    src   Exposed-modules:   Text.Digestive.Forms.Happstack   Build-depends:     base >= 4 && < 5,-                     digestive-functors == 0.0.2.*,+                     digestive-functors == 0.1.0.*,                      happstack-server >= 6.0 && < 6.1,                      utf8-string >= 0.3,                      bytestring >= 0.9,
src/Text/Digestive/Forms/Happstack.hs view
@@ -10,43 +10,47 @@  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 (..), lookInput+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-    getInputString inp =-        case inputValue inp of-          (Right bs) -> Just . LB.toString $ bs-          _          -> Nothing-    getInputText inp =-        case inputValue inp of-          (Right bs) -> Just . Text.toStrict . Text.decodeUtf8 $ bs-          _          -> Nothing+instance FormInput [Input] (String, FilePath) where+    getInputStrings inps =+        map LB.toString $ rights $ map inputValue inps -    getInputFile inp =-        case inputValue inp of-          (Left fp) ->-              do fn <- inputFilename inp-                 return (fn, fp)+    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 e v a = Form m Input e v a+type HappstackForm m e v a = Form m [Input] e v a  -- | Environment that will fetch input from the parameters parsed by Happstack -- happstackEnvironment :: (HasRqData m, MonadPlus m, Alternative m)-                     => Environment m Input-happstackEnvironment = Environment $ optional . lookInput . show+                     => Environment m [Input]+happstackEnvironment = Environment $ fmap toMaybe . lookInputs . show+    where+      toMaybe :: [a] -> Maybe [a]+      toMaybe [] = Nothing+      toMaybe l  = Just l  -- | Run a happstack form --