Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/pbrisbin/yesod-comments
Drop-in comments module for a Yesod application
https://github.com/pbrisbin/yesod-comments
Last synced: 3 months ago
JSON representation
Drop-in comments module for a Yesod application
- Host: GitHub
- URL: https://github.com/pbrisbin/yesod-comments
- Owner: pbrisbin
- License: bsd-3-clause
- Created: 2010-10-26T21:04:07.000Z (about 14 years ago)
- Default Branch: master
- Last Pushed: 2014-07-28T19:24:09.000Z (over 10 years ago)
- Last Synced: 2024-04-26T05:31:32.126Z (9 months ago)
- Language: Haskell
- Homepage:
- Size: 385 KB
- Stars: 10
- Watchers: 4
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Yesod Comments
A drop-in comments module for a Yesod application.
## Installation
~~~ { .bash }
# Stable
$ cabal install yesod-coments# Development
$ git clone https://github.com/pbrisbin/yesod-comments
$ cd yesod-comments
$ cabal install
~~~## Usage
Make your foundation type an instance of `YesodComments`:
~~~ { .haskell }
import Yesod.Commentsinstance YesodComments MySite where
--
-- Store comments using YesodPersist. It's the only backend
-- available at this time.
--
commentStorage = persistStorage--
-- userDetails :: UserId -> Handler (Maybe UserDetails)
--
-- This maps an AuthId m to more useful details like friendly name
-- and email address.
--
userDetails = undefined
~~~Next, add comments to some view somewhere. You only have to provide a
unique thread identifier, and the widget will handle showing existing
comments and a form for submitting new ones.**Note**: Users must be authenticated to comment, therefore your site
must be an instance of `YesodAuth` in order to use `YesodComments`.~~~ { .haskell }
-- addComments handles displaying the form on GET and processing it on
-- POST, this follows the common Yesod idiom of handling both methods
-- with one handler:getPostR :: String -> Handler RepHtml
getPostR slug = do
post <- getPostBySlug slugdefaultLayout $ do
setTitle "A post"[whamlet|
#{postContent post}
#{addComments slug}
|]postPostR :: String -> Handler RepHtml
postPostR = getPostR
~~~Finally, add a `migrateComments` call to your Application runner.
~~~ { .haskell }
makeFoundation :: AppConfig DefaultEnv () -> Logger -> IO MySite
makeFoundation conf setLogger = do
--
-- ...
--
Database.Persist.Store.runPool dbconf (runMigration migrateComments) p
return $ MySite conf setLogger s p manager dbconf
~~~## Administration
An administration subsite is provided to allow users to edit and delete
comments they've left themselves. Any additional moderation must be done
manually (for now).Add the subsite to your routes:
~~~
/comments CommentsAdminR CommentsAdmin getCommentsAdmin
~~~Optionally, define a few more functions in the `YesodComments` instance:
~~~ { .haskell }
instance YesodComments MySite where
--
-- ...
---- How to get from a thread identifier to the page where it resides,
-- this is used to provide links back from the "my comments" page
threadRoute = Just $ \thread -> PostR thread-- How to get to the subsite's Edit action for a comment
editRoute = Just $ \thread cid -> CommentsAdminR $ EditCommentR thread cid-- How to get to the subsite's Delete action for a comment
deleteRoute = Just $ \thread cid -> CommentsAdminR $ DeleteCommentR thread cid
~~~With these defined, Edit and Delete links will appear whenever a user
sees a comment they've left.## Styling
There is no styling provided by this library, but the markup is designed
for Twitter's Bootstrap. If you use that, it should look OK out of the
box. Even if you don't, the `div`s that Bootstrap requires should be
more than adequate for creating your own styles.