Commentable Plugin supported by Pivotal

  • Tags: comment
  • Latest: 0.8.1
  • Last Updated: 06 March 2012
  • Grails version: 1.1 > *
11 votes
Dependency:
compile ":commentable:0.8.1"

 Documentation  Issues

Summary

Adds support for comments. Mark up any of your domain classes as having comments and then use the tag library and partial templates to integrate comments into your views.

Description

Commentable Plugin

This plugin provides a generic way to add and manage comments for a given application. The plugin is used on grails.org and you can see a demo of it working in the Screencasts or Blog sections of the site.

Requirements

  • Grails Version: 1.1 and above
  • JDK: 1.5 and above

Installation

grails install-plugin commentable

Usage

Implement the Commentable interface:

import org.grails.comments.*

class Vehicle implements Commentable { }

Add some comments:

def user = User.get(1)
def v = Vehicle.get(1)

v.addComment(user, "I prefer red cars") .addComment(user, "I prefer sporty cars")

Query:

def v = Vehicle.get(1)
v.comments.each { println it.body }

In a GSP:

<comments:each bean="${vehicle}">
     ${comment.body} - Posted by ${comment.poster}
</comments:each>

The plugin also features a generic commenting UI component. To use you may need to define a poster evaluator in grails-app/conf/Config.groovy. The default one looks like:

grails.commentable.poster.evaluator = { request.user }

But if you store users in the session instead you may want this to be:

grails.commentable.poster.evaluator = { session.user }

You can then use the <comments:render> tag to render all comments with a comment editor:

<comments:render bean="${vehicle}" />

Post Comment:

To add some logic to handle newly created comments, just add an "onAddComment()" method to your Commentable domain class:

class MyThing implements Commentable {
    String name

def onAddComment = { comment -> // post processing logic for newly added comment } }

}

History

2011-01-18 0.8.0 Release

  • Upgraded to Grails 2.0.1 and added controller action for deleting comments
2011-01-18 0.7.7 Release 2011-01-09 0.7.6 Release
  • Upgraded to Grails 2
  • Fixed metadata for Grails 2 compatibility
2009-10-11 0.7.5 Release
  • Fixed a small bug in _comments.gsp that was causing problems with CSS.