packages feed

digestive-functors-happstack (empty) → 0.0.2.0

raw patch · 4 files changed

+108/−0 lines, 4 filesdep +basedep +bytestringdep +digestive-functorssetup-changed

Dependencies added: base, bytestring, digestive-functors, happstack-server, utf8-string

Files

+ LICENSE view
@@ -0,0 +1,31 @@+Copyright (c) 2010, Jasper Van der Jeugt+All rights reserved.+Redistribution and use in source and binary forms, with or without+modification, are permitted provided that the following conditions are+met:+    * Redistributions of source code must retain the above copyright+      notice, this list of conditions and the following disclaimer.+    * Redistributions in binary form must reproduce the above+      copyright notice, this list of conditions and the following+      disclaimer in the documentation and/or other materials provided+      with the distribution.+    * Neither the name of Jasper Van der Jeugt nor the names of other+      contributors may be used to endorse or promote products derived+      from this software without specific prior written permission.+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ digestive-functors-happstack.cabal view
@@ -0,0 +1,24 @@+Name:                digestive-functors-happstack+Version:             0.0.2.0+Synopsis:            Happstack backend for the digestive-functors library+Description:         This is a 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+Category:            Web+Build-type:          Simple+Cabal-version:       >=1.6+++Library+  Hs-source-dirs:    src+  Exposed-modules:   Text.Digestive.Forms.Happstack+  Build-depends:     base >= 4 && < 5,+                     digestive-functors == 0.0.2.*,+                     happstack-server >= 0.5 && < 0.6,+                     utf8-string >= 0.3,+                     bytestring >= 0.9
+ src/Text/Digestive/Forms/Happstack.hs view
@@ -0,0 +1,51 @@+-- | Module providing a happstack backend for the digestive-functors library+--+{-# LANGUAGE FlexibleInstances, MultiParamTypeClasses #-}+module Text.Digestive.Forms.Happstack+    ( HappstackForm+    , happstackEnvironment+    , eitherHappstackForm+    ) where++import Control.Monad (liftM)++import Data.ByteString.Lazy as LB+import Data.ByteString.Lazy.UTF8 as LB (toString)+import Happstack.Server ( Input (..), ServerPartT, getDataFn, lookInput+                        , Method (..), withRequest, runServerPartT, rqMethod+                        )++import Text.Digestive.Forms (FormInput (..))+import Text.Digestive.Types (Form (..), Environment (..), viewForm, eitherForm)++instance FormInput Input (String, LB.ByteString) where+    getInputString = Just . LB.toString . inputValue+    getInputFile inp = do+        inputFilename' <- inputFilename inp+        return (inputFilename', inputValue inp)++-- | Simplification of the `Form` type, instantiated to Happstack+--+type HappstackForm m e v a = Form (ServerPartT m) Input e v a++-- | Environment that will fetch input from the parameters parsed by Happstack+--+happstackEnvironment :: (Monad m) => Environment (ServerPartT m) Input+happstackEnvironment = Environment $ getDataFn . lookInput . show++-- | 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 :: (Monad m, Functor m)+                    => HappstackForm m e v a       -- ^ Form+                    -> String                      -- ^ Form name+                    -> ServerPartT m (Either v a)  -- ^ Result+eitherHappstackForm form name = withRequest $ \rq -> flip runServerPartT rq $+    case rqMethod rq of GET -> liftM Left $ viewForm form name+                        _   -> eitherForm form name happstackEnvironment