Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
jaspervdj committed Dec 9, 2010
1 parent 2c41911 commit 289e7d3
Show file tree
Hide file tree
Showing 6 changed files with 104 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
*.hi
*.o
*.swp
dist
30 changes: 30 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -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.
5 changes: 5 additions & 0 deletions README.markdown
Original file line number Diff line number Diff line change
@@ -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.
2 changes: 2 additions & 0 deletions Setup.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import Distribution.Simple
main = defaultMain
44 changes: 44 additions & 0 deletions Text/Digestive/Forms/Happstack.hs
Original file line number Diff line number Diff line change
@@ -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
22 changes: 22 additions & 0 deletions digestive-functors-happstack.cabal
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 289e7d3

Please sign in to comment.