packages feed

scotty 0.4.3 → 0.4.4

raw patch · 4 files changed

+15/−5 lines, 4 files

Files

Web/Scotty.hs view
@@ -26,7 +26,7 @@       -- ** Exceptions     , raise, rescue, next       -- * Types-    , ScottyM, ActionM, Param, Parsable, RoutePattern+    , ScottyM, ActionM, Param, Parsable(..), readEither, RoutePattern     ) where  import Blaze.ByteString.Builder (fromByteString)
Web/Scotty/Action.hs view
@@ -4,7 +4,7 @@     , status, header, redirect     , text, html, file, json, source     , raise, rescue, next-    , ActionM, Parsable, Param, runAction+    , ActionM, Parsable(..), readEither, Param, runAction     ) where  import Blaze.ByteString.Builder (Builder, fromLazyByteString)@@ -119,21 +119,28 @@         Nothing -> raise $ mconcat ["Param: ", k, " not found!"]         Just v  -> either (const next) return $ parseParam v +-- | Minimum implemention: 'parseParam' class Parsable a where+    -- | Take a 'T.Text' value and parse it as 'a', or fail with a message.     parseParam :: T.Text -> Either T.Text a -    -- if any individual element fails to parse, the whole list fails to parse.+    -- | Default implementation parses comma-delimited lists.+    --+    -- > parseParamList t = mapM parseParam (T.split (== ',') t)     parseParamList :: T.Text -> Either T.Text [a]     parseParamList t = mapM parseParam (T.split (== ',') t)  -- No point using 'read' for Text, ByteString, Char, and String. instance Parsable T.Text where parseParam = Right instance Parsable B.ByteString where parseParam = Right . lazyTextToStrictByteString+-- | Overrides default 'parseParamList' to parse String. instance Parsable Char where     parseParam t = case T.unpack t of                     [c] -> Right c                     _   -> Left "parseParam Char: no parse"     parseParamList = Right . T.unpack -- String+-- | Checks if parameter is present and is null-valued, not a literal '()'.+-- If the URI requested is: '/foo?bar=()&baz' then 'baz' will parse as (), where 'bar' will not. instance Parsable () where     parseParam t = if T.null t then Right () else Left "parseParam Unit: no parse" @@ -145,6 +152,9 @@ instance Parsable Int where parseParam = readEither instance Parsable Integer where parseParam = readEither +-- | Useful for creating 'Parsable' instances for things that already implement 'Read'. Ex:+--+-- > instance Parsable Int where parseParam = readEither readEither :: (Read a) => T.Text -> Either T.Text a readEither t = case [ x | (x,"") <- reads (T.unpack t) ] of                 [x] -> Right x
examples/json.hs view
@@ -24,7 +24,7 @@ main :: IO () main = scotty 3000 $ do     middleware logStdoutDev-    middleware $ staticRoot "static"+    middleware $ staticPolicy (noDots >-> addBase "static")      get "/" $ do         html $ wrapper $ do
scotty.cabal view
@@ -1,5 +1,5 @@ Name:                scotty-Version:             0.4.3+Version:             0.4.4 Synopsis:            Haskell web framework inspired by Ruby's Sinatra, using WAI and Warp Homepage:            https://github.com/xich/scotty Bug-reports:         https://github.com/xich/scotty/issues