Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Initial commit

  • Loading branch information...
commit 289e7d33a81094cb514e6545830626394096ad4c 1 parent 2c41911
@jaspervdj authored
View
1  .gitignore
@@ -1,3 +1,4 @@
*.hi
*.o
*.swp
+dist
View
30 LICENSE
@@ -0,0 +1,30 @@
+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 Jeremy Shaw 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.
View
5 README.markdown
@@ -0,0 +1,5 @@
+digestive-functors-happstack
+============================
+
+This is simply a [Happstack](http://happstack.com) backend for the
+[digestive-functors](http://github.com/jaspervdj/digestive-functors) library.
View
2  Setup.hs
@@ -0,0 +1,2 @@
+import Distribution.Simple
+main = defaultMain
View
44 Text/Digestive/Forms/Happstack.hs
@@ -0,0 +1,44 @@
+-- | Module providing a happstack backend for the digestive-functors library
+--
+module Text.Digestive.Forms.Happstack
+ ( happstackEnvironment
+ , eitherHappstackForm
+ ) where
+
+import Control.Arrow ((&&&))
+import Control.Monad (liftM)
+import Data.Maybe (fromMaybe)
+
+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 where
+ getInputString = LB.toString . inputValue
+ getInputFile = fromMaybe "" . inputFilename &&& inputValue
+
+-- | 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)
+ => Form (ServerPartT m) Input 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
View
22 digestive-functors-happstack.cabal
@@ -0,0 +1,22 @@
+Name: digestive-functors-happstack
+Version: 0.0.1
+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-happstack
+License: BSD3
+License-file: LICENSE
+Author: Jasper Van der Jeugt
+Maintainer: jaspervdj@gmail.com
+Category: Web
+Build-type: Simple
+Cabal-version: >=1.2
+
+
+Library
+ Exposed-modules: Text.Digestive.Forms.Happstack
+ Build-depends: base >= 4 && < 5,
+ digestive-functors == 0.0.1,
+ happstack-server >= 0.5 && < 0.6,
+ utf8-string >= 0.3
Please sign in to comment.
Something went wrong with that request. Please try again.