packages feed

fn 0.1.0.0 → 0.1.1.0

raw patch · 4 files changed

+14/−55 lines, 4 filesPVP: major bump suggested

API removals or changes: PVP suggests a major version bump

API changes (from Hackage documentation)

- Web.Fn: class Param a
- Web.Fn: instance Web.Fn.Param Data.Text.Internal.Text
- Web.Fn: instance Web.Fn.Param GHC.Types.Double
- Web.Fn: instance Web.Fn.Param GHC.Types.Int
+ Web.Fn: class FromParam a
+ Web.Fn: instance Web.Fn.FromParam Data.Text.Internal.Text
+ Web.Fn: instance Web.Fn.FromParam GHC.Types.Double
+ Web.Fn: instance Web.Fn.FromParam GHC.Types.Int
- Web.Fn: fromParam :: Param a => Text -> Either Text a
+ Web.Fn: fromParam :: FromParam a => Text -> Either Text a
- Web.Fn: param :: Param p => Text -> Req -> (p -> a) -> Maybe (Req, a)
+ Web.Fn: param :: FromParam p => Text -> Req -> (p -> a) -> Maybe (Req, a)
- Web.Fn: paramOptional :: Param p => Text -> Req -> (Either Text p -> a) -> Maybe (Req, a)
+ Web.Fn: paramOptional :: FromParam p => Text -> Req -> (Either Text p -> a) -> Maybe (Req, a)
- Web.Fn: paramPresent :: Param 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: segment :: Param p => Req -> (p -> a) -> Maybe (Req, a)
+ Web.Fn: segment :: FromParam p => Req -> (p -> a) -> Maybe (Req, a)

Files

CHANGELOG.md view
@@ -1,3 +1,7 @@+* 0.1.1.0 Daniel Patterson <dbp@dbpmail.net> 2015-10-26++  Rename `Param` class to `FromParam`.+ * 0.1.0.0 Daniel Patterson <dbp@dbpmail.net> 2015-10-25    Initial release.
README.md view
@@ -50,48 +50,3 @@ handler _ fragment i = okText (fragment <> " - " <> T.pack (show i))  ```--## Recommended Pairings--Part of the design of `Fn` is that you won't need a suite of `fn-foo`-libraries that generally serve to adapt the functions from `foo` to-the monad transformer stack of the web framework of choice (we may add-an `fn-extra` package with a few helpers in it in the future, but it'll-be small). Still, it's helpful to know what are common tools that are-well designed and tested, so here are a list (those marked with `[*]`-are used in the example application included in the repository):--- [warp](http://hackage.haskell.org/package/warp)`[*]`: perhaps obvious,-  but you will need to choose an HTTP server to use with your `Fn`-  application, and `warp` is the defacto standard for applications that-  use the `WAI` interface that `Fn` does.-- [heist](http://hackage.haskell.org/package/heist)`[*]`: a wonderful-  templating system that is both really simple (the templates are just-  html) and powerful (any html tag can be bound to run haskell-  code). This may be the one place where we may add some adaptors, as-  it would be wonderful to have splices (those haskell-bound html-  tags) that were normal functions, rather than monadic.-- [postgresql-simple](https://hackage.haskell.org/package/postgresql-simple)`[*]`:-  a well designed interface to PostgreSQL; ofter the lower level way-  to interact with the database (setting up connections, etc), if you-  use a higher level, safer abstraction like `opaleye` (below) for actual-  queries. Use it with-  [resource-pool](https://hackage.haskell.org/package/resource-pool)`[*]`-  to have it manage many connections.-- [opaleye](https://hackage.haskell.org/package/opaleye): a type-safe-  composable way to write database queries against PostgreSQL.-- [hedis](https://hackage.haskell.org/package/hedis)`[*]`: a full-featured-  client for the key-value store Redis.-- [logging](https://hackage.haskell.org/package/logging)`[*]`: a simple-  library for writing log messages, which allow you to change the-  logging level and suppress some subset of messages.-- [hspec](https://hackage.haskell.org/package/hspec)`[*]`: a-  full-featured testing framework. Use with-  [hspec-wai](https://hackage.haskell.org/package/hspec-wai)`[*]` --  though the latter could use some work to make it do everything it-  needs to!-- [wai-session](https://hackage.haskell.org/package/wai-session)`[*]`:-  Combine with something like-  [wai-session-clientsession](https://hackage.haskell.org/package/wai-session-clientsession)`[*]`-  to store session data in encrypted cookies (like, who a user is-  logged in as).
fn.cabal view
@@ -1,5 +1,5 @@ name:                fn-version:             0.1.0.0+version:             0.1.1.0 synopsis:            A functional web framework. description:         Please see README. homepage:            http://github.com/dbp/fn#readme
src/Web/Fn.hs view
@@ -34,7 +34,7 @@               , path               , end               , segment-              , Param(..)+              , FromParam(..)               , param               , paramOptional               , paramPresent@@ -188,7 +188,7 @@ -- | Captures a part of the path. It will parse the part into the type -- specified by the handler it is matched to. If there is no segment, or -- if the segment cannot be parsed as such, it won't match.-segment :: Param p => Req -> (p -> a) -> Maybe (Req, a)+segment :: FromParam p => Req -> (p -> a) -> Maybe (Req, a) segment req k =   case fst req of     (x:xs) -> case fromParam x of@@ -198,18 +198,18 @@  -- | A class that is used for parsing for 'param', 'paramOptional', -- 'paramPresent', and 'segment'.-class Param a where+class FromParam a where   fromParam :: Text -> Either Text a -instance Param Text where+instance FromParam Text where   fromParam = Right-instance Param Int where+instance FromParam Int where   fromParam t = case decimal t of                   Left msg -> Left (T.pack msg)                   Right m | snd m /= "" ->                             Left ("Incomplete match: " <> T.pack (show m))                   Right (v, _) -> Right v-instance Param Double where+instance FromParam Double where   fromParam t = case double t of                   Left msg -> Left (T.pack msg)                   Right m | snd m /= "" ->@@ -219,7 +219,7 @@ -- | Matches on a query parameter of the given name. If there is no -- parameter, or it cannot be parsed into the type needed by the -- handler, it won't match.-param :: Param p => Text -> Req -> (p -> a) -> Maybe (Req, a)+param :: FromParam p => Text -> Req -> (p -> a) -> Maybe (Req, a) param n req k =   let match = find ((== T.encodeUtf8 n) . fst) (snd req)   in case (maybe "" T.decodeUtf8 . snd) <$> match of@@ -232,7 +232,7 @@ -- 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 :: Param p =>+paramOptional :: FromParam p =>                  Text ->                  Req ->                  (Either Text p -> a) ->@@ -245,7 +245,7 @@        Just p' -> Just (req, k (fromParam p'))  -- | Matches a query parameter, which must be present, but can fail to parse.-paramPresent :: Param p =>+paramPresent :: FromParam p =>                 Text ->                 Req ->                 (Either Text p -> a) ->