yesod-comments 0.8.0 → 0.8.1
raw patch · 5 files changed
+32/−30 lines, 5 filesdep ~bytestringdep ~persistentdep ~yesod-form
Dependency ranges changed: bytestring, persistent, yesod-form, yesod-markdown
Files
- Yesod/Comments/Core.hs +9/−7
- Yesod/Comments/Form.hs +4/−5
- Yesod/Comments/Management.hs +4/−2
- Yesod/Comments/Utils.hs +3/−4
- yesod-comments.cabal +12/−12
Yesod/Comments/Core.hs view
@@ -31,7 +31,7 @@ type ThreadId = Text type CommentId = Int --- | The core data type a Comment+-- | The core data type, a Comment data Comment = Comment { commentId :: CommentId , cThreadId :: ThreadId@@ -46,24 +46,26 @@ instance Eq Comment where a == b = (cThreadId a == cThreadId b) && (commentId a == commentId b) --- | Information about the User that's needed to store comments.+-- | Information about the User needed to store comments. data UserDetails = UserDetails- { textUserName :: Text -- ^ Text version of user id, @toPathPiece- -- userId@ is recommended. comments are stored+ { textUserId :: Text -- ^ Text version of a user id, @toPathPiece+ -- userId@ is recommended. Comments are stored -- using this value so users can freely change -- names without losing comments. , friendlyName :: Text -- ^ The name that's actually displayed , emailAddress :: Text -- ^ Not shown but stored } deriving Eq --- | How to save and restore comments from persisten storage. All necesary--- actions are accomplished through these 5 functions. Currently, only--- @persistStorage@ is available.+-- | How to save and restore comments from persistent storage. All+-- necessary actions are accomplished through these 5 functions.+-- Currently, only @persistStorage@ is available. data CommentStorage s m = CommentStorage { csGet :: ThreadId -> CommentId -> GHandler s m (Maybe Comment) , csStore :: Comment -> GHandler s m () , csUpdate :: Comment -> Comment -> GHandler s m () , csDelete :: Comment -> GHandler s m ()++ -- | Pass @Nothing@ to get all comments site-wide. , csLoad :: Maybe ThreadId -> GHandler s m [Comment] }
Yesod/Comments/Form.hs view
@@ -50,7 +50,7 @@ , cThreadId = formThread cf , cTimeStamp = now , cIpAddress = T.pack ip- , cUserName = textUserName $ formUser cf+ , cUserName = textUserId $ formUser cf , cUserEmail = emailAddress $ formUser cf , cContent = formComment cf , cIsAuth = True@@ -66,8 +66,7 @@ commentForm :: RenderMessage m FormMessage => ThreadId -> UserDetails -> Maybe Comment -> Form s m CommentForm commentForm thread udetails mcomment = renderBootstrap $ CommentForm- <$> pure udetails- <*> pure thread+ <$> pure udetails <*> pure thread <*> areq markdownField commentLabel (fmap cContent mcomment) where@@ -85,8 +84,8 @@ -- redirect to current route maybe notFound (redirect . tm) =<< getCurrentRoute --- | Both handle form submission and present form HTML. On FormSuccess, run--- the given function on the submitted value.+-- | Both handle form submission and present form HTML. On @FormSuccess@,+-- run the given function on the submitted value. runFormWith :: YesodComments m => Maybe Comment -> (CommentForm -> GHandler s m ())
Yesod/Comments/Management.hs view
@@ -118,8 +118,8 @@ latest' :: [Comment] -> UTCTime latest' = maximum . map cTimeStamp --- | Halts with @permissionDenied@ or runs the action if the comment--- belongs to the currently logged in user+-- | If the comment belongs to the currently logged in user, runs the+-- action on it. Otherwise, halts with @permissionDenied@. withUserComment :: YesodComments m => ThreadId -> CommentId -> (Comment -> GHandler s m RepHtml) -> GHandler s m RepHtml withUserComment thread cid f = do mcomment <- csGet commentStorage thread cid@@ -136,8 +136,10 @@ runFormEdit :: YesodComments m => Comment -> ThreadId -> Maybe UserDetails -> GWidget CommentsAdmin m () runFormEdit comment = runFormWith (Just comment) $ \cf -> do tm <- getRouteToMaster+ csUpdate commentStorage comment $ comment { cContent = formComment cf } setMessage "comment updated."+ redirect $ tm CommentsR layout :: Yesod m => Text -> GWidget s m () -> GHandler s m RepHtml
Yesod/Comments/Utils.hs view
@@ -47,7 +47,7 @@ Just uid -> userDetails uid _ -> return Nothing --- | Halts with @permissionDenied@ if user is not authorized+-- | Halts with @permissionDenied@ if user is not authenticated requireUserDetails :: YesodComments m => GHandler s m (UserDetails) requireUserDetails = do mudetails <- currentUserDetails@@ -60,9 +60,8 @@ defaultUserDetails :: Comment -> UserDetails defaultUserDetails c = UserDetails (cUserName c) (cUserName c) (cUserEmail c) -gravatar :: Int -- ^ size- -> Text -- ^ email- -> String+-- | Given pixel size and email, return the gravatar url+gravatar :: Int -> Text -> String gravatar s = G.gravatar defaultConfig { gDefault = Just MM, gSize = Just $ Size s } isCommentingUser :: YesodComments m => Comment -> GHandler s m Bool
yesod-comments.cabal view
@@ -1,5 +1,5 @@ name: yesod-comments-version: 0.8.0+version: 0.8.1 synopsis: A generic comments interface for a Yesod application description: A generic comments interface for a Yesod application homepage: http://github.com/pbrisbin/yesod-comments@@ -22,17 +22,17 @@ , Yesod.Comments.Management -- Packages needed in order to build this package.- build-depends: base >= 4 && < 5- , text >= 0.11 && < 0.12- , bytestring >= 0.9.1 && < 0.10- , friendly-time >= 0.2 && < 0.3- , gravatar >= 0.5 && < 0.6- , persistent >= 1.0 && < 1.1- , wai >= 1.3 && < 1.4- , yesod >= 1.1 && < 1.2- , yesod-auth >= 1.1 && < 1.2- , yesod-form >= 1.1 && < 1.2- , yesod-markdown >= 0.4 && < 0.5+ build-depends: base >= 4 && < 5+ , text >= 0.11 && < 0.12+ , bytestring >= 0.9.1 && < 0.11+ , friendly-time >= 0.2 && < 0.3+ , gravatar >= 0.5 && < 0.6+ , persistent >= 1.0 && < 1.2+ , wai >= 1.3 && < 1.4+ , yesod >= 1.1 && < 1.2+ , yesod-auth >= 1.1 && < 1.2+ , yesod-form >= 1.1 && < 1.3+ , yesod-markdown >= 0.4 && < 0.7 , template-haskell , directory