forked from jaspervdj/digestive-functors
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
104 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
*.hi | ||
*.o | ||
*.swp | ||
dist |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
import Distribution.Simple | ||
main = defaultMain |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |