packages feed

fn 0.1.1.0 → 0.1.2.0

raw patch · 4 files changed

+20/−38 lines, 4 filesPVP: major bump suggested

API removals or changes: PVP suggests a major version bump

API changes (from Hackage documentation)

- Web.Fn: paramOptional :: FromParam p => Text -> Req -> (Either Text p -> a) -> Maybe (Req, a)
- Web.Fn: paramPresent :: FromParam p => Text -> Req -> (Either Text p -> a) -> Maybe (Req, a)
+ Web.Fn: paramOpt :: FromParam p => Text -> Req -> (Either Text p -> a) -> Maybe (Req, a)

Files

CHANGELOG.md view
@@ -1,3 +1,9 @@+* 0.1.2.0 Daniel Pattersion <dbp@dbpmail.net> 2015-10-27++  Rename `paramOptional` to `paramOpt`, to match `fn-extra`'s `Heist`+  naming of `attr` and `attrOpt`. Remove `paramPresent`, because you+  can get that behavior by parsing to `Text`.+ * 0.1.1.0 Daniel Patterson <dbp@dbpmail.net> 2015-10-26    Rename `Param` class to `FromParam`.
fn.cabal view
@@ -1,5 +1,5 @@ name:                fn-version:             0.1.1.0+version:             0.1.2.0 synopsis:            A functional web framework. description:         Please see README. homepage:            http://github.com/dbp/fn#readme
src/Web/Fn.hs view
@@ -36,8 +36,7 @@               , segment               , FromParam(..)               , param-              , paramOptional-              , paramPresent+              , paramOpt                 -- * Responses               , okText               , okHtml@@ -196,8 +195,8 @@                 Right p -> Just ((xs, snd req), k p)     _     -> Nothing --- | A class that is used for parsing for 'param', 'paramOptional',--- 'paramPresent', and 'segment'.+-- | A class that is used for parsing for 'param', 'paramOpt', and+-- 'segment'. class FromParam a where   fromParam :: Text -> Either Text a @@ -232,31 +231,17 @@ -- type needed by the handler, but if it isn't present or cannot be -- parsed, the handler will still be called (just with the 'Left' -- variant).-paramOptional :: FromParam p =>-                 Text ->-                 Req ->-                 (Either Text p -> a) ->-                 Maybe (Req, a)-paramOptional n req k =+paramOpt :: FromParam p =>+            Text ->+            Req ->+            (Either Text p -> a) ->+            Maybe (Req, a)+paramOpt n req k =   let match = find ((== T.encodeUtf8 n) . fst) (snd req)       p = ((maybe "" T.decodeUtf8 . snd) <$> match)   in case p of        Nothing -> Just (req, k (Left "param missing"))        Just p' -> Just (req, k (fromParam p'))---- | Matches a query parameter, which must be present, but can fail to parse.-paramPresent :: FromParam p =>-                Text ->-                Req ->-                (Either Text p -> a) ->-                Maybe (Req, a)-paramPresent n req k =-  let match = find ((== T.encodeUtf8 n) . fst) (snd req)-      p = ((maybe "" T.decodeUtf8 . snd) <$> match)-  in case p of-       Nothing -> Nothing-       Just p' -> Just (req, k (fromParam p'))-  returnText :: Text -> Status -> ByteString -> IO (Maybe Response) returnText text status content =
test/Spec.hs view
@@ -109,21 +109,12 @@          (segment // path "b" ==> \_ x -> x == ("a" :: Text))            (R (["a"], []))            `shouldSatisfy` isNothing-    it "should always pass a value with paramOptional" $-      do paramOptional "id" ([], []) (isLeft :: Either Text Text -> Bool)-                       `shouldSatisfy` (snd . fromJust)-         paramOptional "id" ([], [("id", Just "foo")])+    it "should always pass a value with paramOpt" $+      do paramOpt "id" ([], []) (isLeft :: Either Text Text -> Bool)+                  `shouldSatisfy` (snd . fromJust)+         paramOpt "id" ([], [("id", Just "foo")])                        (== Right ("foo" :: Text))                        `shouldSatisfy` (snd . fromJust)-    it "should succeed if present, even if unparsable, w/ paramPresent" $-      do paramPresent "id" ([], []) (isLeft :: Either Text Text -> Bool)-                      `shouldSatisfy` isNothing-         paramPresent "id" ([], [("id", Just "foo")])-                      (== Right ("foo" :: Text))-                      `shouldSatisfy` (snd . fromJust)-         paramPresent "id" ([], [("id", Just "foo")])-                      (isLeft :: Either Text Int -> Bool)-                      `shouldSatisfy` (snd . fromJust)     it "should match end against no further path segments" $       do end ([],[]) () `shouldSatisfy` isJust          end ([],[("foo", Nothing)]) () `shouldSatisfy` isJust