digestive-functors-scotty (empty) → 0.1.0.0
raw patch · 4 files changed
+99/−0 lines, 4 filesdep +basedep +bytestringdep +digestive-functorssetup-changed
Dependencies added: base, bytestring, digestive-functors, http-types, scotty, text, wai, wai-extra
Files
- LICENSE +30/−0
- Setup.hs +2/−0
- digestive-functors-scotty.cabal +32/−0
- src/Text/Digestive/Scotty.hs +35/−0
+ LICENSE view
@@ -0,0 +1,30 @@+Copyright (c) 2013, Martins Macs++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 Martins Macs 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-scotty.cabal view
@@ -0,0 +1,32 @@+name: digestive-functors-scotty+version: 0.1.0.0+synopsis: Scotty backend for the digestive-functors library+description: Scotty backend for the digestive-functors library+homepage: https://bitbucket.org/wniare/digestive-functors-scotty+license: BSD3+license-file: LICENSE+author: Mārtiņš Mačs+maintainer: macs.martins@gmail.com+category: Web+build-type: Simple+cabal-version: >=1.8++library+ hs-source-dirs: src+ GHC-options: -Wall -fwarn-tabs++ exposed-modules: Text.Digestive.Scotty++ build-depends: base ==4.5.*+ , digestive-functors ==0.6.*+ , scotty ==0.5.*+ , bytestring ==0.9.*+ , http-types ==0.8.*+ , text ==0.11.*+ , wai ==1.4.*+ , wai-extra ==1.3.*++source-repository head+ Type: git+ Location: https://bitbucket.org/wniare/digestive-functors-scotty+
+ src/Text/Digestive/Scotty.hs view
@@ -0,0 +1,35 @@+-- | Module providing a scotty backend for the digestive-functors library+module Text.Digestive.Scotty+ ( runForm+ ) where++import Control.Monad ( liftM )+import qualified Data.Text as T+import qualified Data.ByteString.Char8 as B+import qualified Data.Text.Lazy as TL+import qualified Web.Scotty.Trans as Scotty+import Network.Wai ( requestMethod )+import Network.Wai.Parse ( fileName )+import Network.HTTP.Types ( methodGet )++import Text.Digestive.Form+import Text.Digestive.Types+import Text.Digestive.View++scottyEnv :: Monad m => Env (Scotty.ActionT m)+scottyEnv path = do+ inputs <- liftM (map $ TextInput . TL.toStrict) $ Scotty.param name `Scotty.rescue` \_ -> return []+ files <- liftM (map (FileInput . B.unpack . fileName . snd) . filter ((== name) . fst)) Scotty.files+ return $ inputs ++ files+ where name = TL.fromStrict . fromPath $ path++-- | Runs a form with the HTTP input provided by Scotty.+runForm :: Monad m+ => T.Text -- ^ Name of the form+ -> Form v (Scotty.ActionT m) a -- ^ Form to run+ -> (Scotty.ActionT m) (View v, Maybe a) -- ^ Result+runForm name form = Scotty.request >>= \rq ->+ if requestMethod rq == methodGet+ then getForm name form >>= \v -> return (v, Nothing)+ else postForm name form scottyEnv+