web-routes-wai (empty) → 0.19
raw patch · 3 files changed
+69/−0 lines, 3 filesdep +basedep +bytestringdep +waisetup-changed
Dependencies added: base, bytestring, wai, web-routes
Files
- Setup.hs +2/−0
- Web/Routes/Wai.hs +48/−0
- web-routes-wai.cabal +19/−0
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ Web/Routes/Wai.hs view
@@ -0,0 +1,48 @@+module Web.Routes.Wai where++import qualified Data.ByteString.Char8 as S+import qualified Data.ByteString.Lazy.Char8 as L+import Network.Wai+import Network.Wai.Enumerator+import Web.Routes.Base+import Web.Routes.PathInfo +import Web.Routes.RouteT (RouteT, runRouteT)+import Web.Routes.Site++handleWai_ :: (url -> String) -> (String -> Either String url) -> String -> ((url -> String) -> url -> Application) -> Application+handleWai_ fromUrl toUrl approot handler =+ \request ->+ do let fUrl = toUrl $ stripOverlap approot $ S.unpack $ pathInfo request+ case fUrl of+ (Left parseError) -> return $ Response Status404 [] $ Right $ fromLBS (L.pack parseError)+ (Right url) -> handler (showString approot . fromUrl) url request++handleWai_1 :: (url -> String) -> (String -> Either String url) -> String -> (String -> Application) -> ((url -> String) -> url -> Application) -> Application+handleWai_1 fromUrl toUrl approot handleError handler =+ \request ->+ do let fUrl = toUrl $ stripOverlap approot $ S.unpack $ pathInfo request+ case fUrl of+ (Left parseError) -> handleError parseError request+ (Right url) -> handler (showString approot . fromUrl) url request+{- +handleWai_2 :: (url -> String) -> (String -> Failing url) -> String -> ((url -> String) -> url -> Application) -> (Request -> IO (Failing Response))+handleWai_2 fromUrl toUrl approot handler =+ \request ->+ do let fUrl = toUrl $ stripOverlap approot $ S.unpack $ pathInfo request+ case fUrl of+ (Failure errs) -> return (Failure errs)+ (Success url) -> fmap Success $ handler (showString approot . fromUrl) url request +-}++handleWai :: (PathInfo url) => String -> ((url -> String) -> url -> Application) -> Application+handleWai approot handler = handleWai_ toPathInfo fromPathInfo approot handler++handleWaiRouteT_ :: (url -> String) -> (String -> Either String url) -> String -> (url -> Request -> RouteT url IO Response) -> Application+handleWaiRouteT_ toPathInfo fromPathInfo approot handler =+ handleWai_ toPathInfo fromPathInfo approot (\toPathInfo' url request -> runRouteT (handler url request) toPathInfo') ++handleWaiRouteT :: (PathInfo url) => String -> (url -> Request -> RouteT url IO Response) -> Application+handleWaiRouteT approot handler = handleWaiRouteT_ toPathInfo fromPathInfo approot handler++waiSite :: Site url Application -> String -> Application+waiSite site approot = handleWai_ (encodePathInfo . formatPathSegments site) (parsePathSegments site . decodePathInfo) approot (handleSite site)
+ web-routes-wai.cabal view
@@ -0,0 +1,19 @@+Name: web-routes-wai+Version: 0.19+License: BSD3+Author: jeremy@seereason.com+Maintainer: partners@seereason.com+Bug-Reports: http://bugzilla.seereason.com/+Category: Web, Language+Synopsis: Library for maintaining correctness of URLs within an application.+Description: A collection of types and functions that ensure that URLs generated by an application are valid. Need more properties here.+Cabal-Version: >= 1.6+Build-type: Simple++Library+ Build-Depends: base >= 4 && < 5, bytestring, wai, web-routes >= 0.22+ Exposed-Modules: Web.Routes.Wai++source-repository head+ type: darcs+ location: http://src.seereason.com/web-routes/