Skip to content

Commit

Permalink
WIP some haddock syntax error with multiline decls
Browse files Browse the repository at this point in the history
  • Loading branch information
Marco Zocca committed Dec 2, 2023
1 parent 6a1fee2 commit 211f4c6
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 14 deletions.
46 changes: 33 additions & 13 deletions Web/Scotty.hs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,22 @@ import Web.Scotty.Internal.Types (ScottyT, ActionT, ErrorHandler, Param, RoutePa
import UnliftIO.Exception (Handler(..), catch)


-- $setup
-- >>> import Control.Monad.IO.Class (liftIO)
-- >>> import qualified Network.HTTP.Client as H
-- >>> import qualified Network.HTTP.Types as H
-- >>> import qualified Data.ByteString.Lazy.Char8 as LBS (unpack)
-- >>> import qualified Web.Scotty as S (scotty, get, text, pathParam)
-- >>> :{
-- let
-- curl :: MonadIO m => String -> m String
-- curl path = liftIO $ do
-- req0 <- H.parseRequest path
-- let req = req0 { H.method = "GET"}
-- mgr <- H.newManager H.defaultManagerSettings
-- (LBS.unpack . H.responseBody) <$> H.httpLbs req mgr
-- :}

type ScottyM = ScottyT IO
type ActionM = ActionT IO

Expand Down Expand Up @@ -410,30 +426,34 @@ notFound = Trans.notFound
-- | Define a route with a 'StdMethod', 'Text' value representing the path spec,
-- and a body ('Action') which modifies the response.
--
-- > addroute GET "/" $ text "beam me up!"
-- > get "/" $ text "beam me up!"
--
-- The path spec can include values starting with a colon, which are interpreted
-- as /captures/. These are named wildcards that can be looked up with 'param'.
-- as /captures/. These are parameters that can be looked up with 'pathParam'.
--
-- > addroute GET "/foo/:bar" $ do
-- > v <- param "bar"
-- > text v
-- >>> :{
-- let server = S.get "/foo/:bar" (S.pathParam "bar" >>= S.text)
-- in do
-- S.scotty 3000 server
--
-- >>> curl http://localhost:3000/foo/something
-- curl "http://localhost:3000/foo/something"
-- :}
-- something
addroute :: StdMethod -> RoutePattern -> ActionM () -> ScottyM ()
addroute = Trans.addroute

-- | Match requests using a regular expression.
-- Named captures are not yet supported.
--
-- > get (regex "^/f(.*)r$") $ do
-- > path <- param "0"
-- > cap <- param "1"
-- > text $ mconcat ["Path: ", path, "\nCapture: ", cap]
-- >>> :{
-- let server = S.get (S.regex "^/f(.*)r$") $ do
-- cap <- S.pathParam "1"
-- S.text ["Capture:", cap]
-- in do
-- S.scotty 3000 server
--
-- >>> curl http://localhost:3000/foo/bar
-- Path: /foo/bar
-- curl "http://localhost:3000/foo/bar"
-- :}
-- Capture: oo/ba
--
regex :: String -> RoutePattern
Expand Down Expand Up @@ -463,7 +483,7 @@ capture = Trans.capture
-- > v <- param "version"
-- > text v
--
-- >>> curl http://localhost:3000/
-- >>> curl "http://localhost:3000/"
-- HTTP/1.1
--
function :: (Request -> Maybe [Param]) -> RoutePattern
Expand Down
3 changes: 2 additions & 1 deletion doctest/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import Test.DocTest (doctest)

main :: IO ()
main = doctest [
"Web"
"Web/Scotty.hs"
, "Web/Scotty/Trans.hs"
, "-XOverloadedStrings"
, "-XLambdaCase"
]
5 changes: 5 additions & 0 deletions scotty.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,14 @@ test-suite doctest
main-is: Main.hs
type: exitcode-stdio-1.0
default-language: Haskell2010
GHC-options: -Wall -threaded -fno-warn-orphans
hs-source-dirs: doctest
build-depends: base
, bytestring
, doctest
, http-client
, http-types
, scotty

benchmark weigh
main-is: Main.hs
Expand Down

0 comments on commit 211f4c6

Please sign in to comment.