web-routes-happstack-0.23.4/0000755000000000000000000000000012040351403014026 5ustar0000000000000000web-routes-happstack-0.23.4/web-routes-happstack.cabal0000644000000000000000000000147412040351403021070 0ustar0000000000000000Name: web-routes-happstack Version: 0.23.4 License: BSD3 License-File: LICENSE Author: jeremy@seereason.com Maintainer: partners@seereason.com Bug-Reports: http://bugzilla.seereason.com/ Category: Web, Language Synopsis: Adds support for using web-routes with Happstack Cabal-Version: >= 1.6 Build-type: Simple Library Build-Depends: base >= 4 && < 5, bytestring >= 0.9 && < 0.11, happstack-server >= 6.6 && <7.2, text == 0.11.*, web-routes >= 0.27.1 Exposed-Modules: Web.Routes.Happstack source-repository head type: darcs location: http://hub.darcs.net/stepcut/web-routes web-routes-happstack-0.23.4/LICENSE0000644000000000000000000000275712040351403015046 0ustar0000000000000000Copyright (c)2010, Jeremy Shaw 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. web-routes-happstack-0.23.4/Setup.hs0000644000000000000000000000005612040351403015463 0ustar0000000000000000import Distribution.Simple main = defaultMain web-routes-happstack-0.23.4/Web/0000755000000000000000000000000012040351403014543 5ustar0000000000000000web-routes-happstack-0.23.4/Web/Routes/0000755000000000000000000000000012040351403016024 5ustar0000000000000000web-routes-happstack-0.23.4/Web/Routes/Happstack.hs0000644000000000000000000000670512040351403020306 0ustar0000000000000000{-# LANGUAGE FlexibleContexts, FlexibleInstances, MultiParamTypeClasses, TypeSynonymInstances, UndecidableInstances, PackageImports #-} module Web.Routes.Happstack where import Control.Applicative ((<$>)) import Control.Monad (MonadPlus(mzero)) import qualified Data.ByteString.Char8 as C import Data.List (intercalate) import Data.Text (Text) import qualified Data.Text as Text import Happstack.Server (Happstack, FilterMonad(..), ServerMonad(..), WebMonad(..), HasRqData(..), ServerPartT, Response, Request(rqPaths), ToMessage(..), dirs, seeOther) import Web.Routes.RouteT (RouteT(RouteT), MonadRoute, URL, showURL, liftRouteT, mapRouteT) import Web.Routes.Site (Site, runSite) instance (ServerMonad m) => ServerMonad (RouteT url m) where askRq = liftRouteT askRq localRq f m = mapRouteT (localRq f) m instance (FilterMonad a m) => FilterMonad a (RouteT url m) where setFilter = liftRouteT . setFilter composeFilter = liftRouteT . composeFilter getFilter = mapRouteT getFilter instance (WebMonad a m) => WebMonad a (RouteT url m) where finishWith = liftRouteT . finishWith instance (HasRqData m) => HasRqData (RouteT url m) where askRqEnv = liftRouteT askRqEnv localRqEnv f m = mapRouteT (localRqEnv f) m rqDataError = liftRouteT . rqDataError instance (Happstack m) => Happstack (RouteT url m) -- | convert a 'Site' to a normal Happstack route -- -- calls 'mzero' if the route can be decoded. -- -- see also: 'implSite_' implSite :: (Functor m, Monad m, MonadPlus m, ServerMonad m) => Text -- ^ "http://example.org" -> Text -- ^ path to this handler, .e.g. "/route/" or "" -> Site url (m a) -- ^ the 'Site' -> m a implSite domain approot siteSpec = do r <- implSite_ domain approot siteSpec case r of (Left _) -> mzero (Right a) -> return a -- | convert a 'Site' to a normal Happstack route -- -- If url decoding fails, it returns @Left "the parse error"@, -- otherwise @Right a@. -- -- see also: 'implSite' implSite_ :: (Functor m, Monad m, MonadPlus m, ServerMonad m) => Text -- ^ "http://example.org" (or "http://example.org:80") -> Text -- ^ path to this handler, .e.g. "/route/" or "" -> Site url (m a) -- ^ the 'Site' -> m (Either String a) implSite_ domain approot siteSpec = dirs (Text.unpack approot) $ do rq <- askRq let f = runSite (domain `Text.append` approot) siteSpec (map Text.pack $ rqPaths rq) case f of (Left parseError) -> return (Left parseError) (Right sp) -> Right <$> (localRq (const $ rq { rqPaths = [] }) sp) {- implSite__ :: (Monad m) => String -> FilePath -> ([ErrorMsg] -> ServerPartT m a) -> Site url (ServerPartT m a) -> (ServerPartT m a) implSite__ domain approot handleError siteSpec = dirs approot $ do rq <- askRq let pathInfo = intercalate "/" (rqPaths rq) f = runSite (domain ++ approot) siteSpec pathInfo case f of (Failure errs) -> handleError errs (Success sp) -> localRq (const $ rq { rqPaths = [] }) sp -} -- | similar to 'seeOther' but takes a 'URL' 'm' as an argument seeOtherURL :: (MonadRoute m, FilterMonad Response m) => URL m -> m Response seeOtherURL url = do otherURL <- showURL url seeOther (Text.unpack otherURL) (toResponse "")