Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Sudhir Nimavat committed Aug 9, 2013
1 parent e97161a commit 0b47377
Show file tree
Hide file tree
Showing 11 changed files with 243 additions and 0 deletions.
31 changes: 31 additions & 0 deletions .classpath
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src/java"/>
<classpathentry kind="src" path="src/groovy"/>
<classpathentry kind="src" path="grails-app/conf"/>
<classpathentry kind="src" path="grails-app/controllers"/>
<classpathentry kind="src" path="grails-app/domain"/>
<classpathentry kind="src" path="grails-app/services"/>
<classpathentry kind="src" path="grails-app/taglib"/>
<classpathentry kind="src" path="test/integration"/>
<classpathentry kind="src" path="test/unit"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="src" path=".link_to_grails_plugins/release-2.2.1/src/groovy">
<attributes>
<attribute name="org.grails.ide.eclipse.core.SOURCE_FOLDER" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" path=".link_to_grails_plugins/release-2.2.1/src/java">
<attributes>
<attribute name="org.grails.ide.eclipse.core.SOURCE_FOLDER" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" path=".link_to_grails_plugins/rest-client-builder-1.0.3/src/groovy">
<attributes>
<attribute name="org.grails.ide.eclipse.core.SOURCE_FOLDER" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.grails.ide.eclipse.core.CLASSPATH_CONTAINER"/>
<classpathentry exported="true" kind="con" path="GROOVY_DSL_SUPPORT"/>
<classpathentry kind="output" path="target/eclipseclasses"/>
</classpath>
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/.settings
/lib
/scripts
/src
/target
/web-app
/test
26 changes: 26 additions & 0 deletions .project
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>facebook-comments</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.grails.ide.eclipse.core.nature</nature>
<nature>org.eclipse.jdt.groovy.core.groovyNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
<linkedResources>
<link>
<name>.link_to_grails_plugins</name>
<type>2</type>
<location>F:/work/github/facebook-comments/target/plugins</location>
</link>
</linkedResources>
</projectDescription>
14 changes: 14 additions & 0 deletions FacebookCommentsGrailsPlugin.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
class FacebookCommentsGrailsPlugin {
def version = "1.0"
def grailsVersion = "1.3 > *"
def title = "Facebook Comments Plugin"
def author = "Sudhir Nimavat"
def authorEmail = "[email protected]"
def description = "Easy Facebook Comments Integration"

def documentation = "http://grails.org/plugin/facebook-comments"
def license = "APACHE"

def issueManagement = [ system: "GITHUB", url: "https://github.com/snimavat/nimble/issues" ]
def scm = [system: 'GitHub', url: 'https://github.com/snimavat/nimble']
}
50 changes: 50 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,53 @@ grails-facebook-comments
========================

Facebook comments grails plugin


## Configuration
-----
Following configuration options are available.

- grails.plugin.facebookcomments.appId
- grails.plugin.facebookcomments.width
- grails.plugin.facebookcomments.colorscheme
- grails.plugin.facebookcomments.num_posts
- grails.plugin.facebookcomments.mobile
- grails.plugin.facebookcomments.href = { bean -> }



All of the config options are optional.
See [facebook documentation](https://developers.facebook.com/docs/reference/plugins/comments/) for details about possible values.

## Integrating facebook comments into your application.
----
Follow this steps for integration

*Step 1*
Put `<fb:initFbCommentsJS appId="your app id" />` right after opening `<body>` tag. It will initialize facebook comments js sdk.
appId parameter is optional and if not specified it will be picked up from config.

*step 2*
put `<fb:comments width="" colorscheme="", num_posts="" mobile="" href="http://example.com"/>` anywhere in the page where you want comments to be displayed.
Again all of the parameters are optional and if not specified they will be picked up from config.

#### Configuring data-href url
-----
href parameter is used identify the page for comments. It can directly specified in `<fb:comments>` tag, or it can be configured as a Closure in config.
When no href parameter is passed to `<fb:comments>` tag, it will check if Closure is configured in config, if so, the closure will be called and return value will be used as href.

*Example*
```
Config.groovy
grails.plugin.facebookcomments.href = { bean -> "http://example.com/page?id=$bean.id" }
```

And now in your gsp file

```
<fb:comments bean="${page}" />
```

When href is not passed as parameter to `<fb:comments />` or not configured in Config.groovy, current request url will be used as href.
4 changes: 4 additions & 0 deletions application.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#Grails Metadata file
#Fri Aug 09 22:02:56 IST 2013
app.grails.version=2.2.4
app.name=facebook-comments
18 changes: 18 additions & 0 deletions grails-app/conf/BuildConfig.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
grails.project.work.dir = 'target'

grails.project.dependency.resolution = {
inherits("global") {
}
log "warn"
repositories {
grailsCentral()
mavenCentral()
mavenLocal()
}
dependencies {
}

plugins {
build ':release:2.2.1', ':rest-client-builder:1.0.3', { export = false }
}
}
10 changes: 10 additions & 0 deletions grails-app/conf/Config.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
log4j = {
appenders {
console name:'stdout', layout:pattern(conversionPattern: '%c{2} %m%n')
}
error 'org.codehaus.groovy.grails',
'org.springframework',
'org.hibernate',
'net.sf.ehcache.hibernate'
debug 'grails.plugin.aspectj'
}
11 changes: 11 additions & 0 deletions grails-app/conf/DataSource.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
dataSource {
pooled = true
driverClassName = "org.h2.Driver"
username = "sa"
password = ""
}
hibernate {
cache.use_second_level_cache = true
cache.use_query_cache = false
cache.region.factory_class = 'net.sf.ehcache.hibernate.EhCacheRegionFactory'
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package grails.plugin.facebookcomments

import groovy.xml.MarkupBuilder

class FacebookCommentTagLib {

static namespace = "fb"

def grailsApplication

def comments = { attrs ->

def settings = grailsApplication.config.grails.plugin?.facebookcomments

def width = attrs.width ?: settings?.width
def colorscheme = attrs.colorscheme ?: settings?.colorscheme
def num_posts = attrs.num_posts ?: settings?.num_posts
def mobile = attrs.mobile ?: settings?.mobile

def href = attrs.href
if(attrs.href) {
href = attrs.href
} else if(settings.href instanceof Closure) {
href = settings.href(attrs.bean)
} else {
href = request.getRequestURL()
}

Map fbAttrs = ["class":"fb-comments"]

addFbAttr(fbAttrs, "width", width)
addFbAttr(fbAttrs, "colorscheme", colorscheme)
addFbAttr(fbAttrs, "num_posts", num_posts)
addFbAttr(fbAttrs, "mobile", mobile)
addFbAttr(fbAttrs, "href", href)

new MarkupBuilder(out).div(fbAttrs)
}

def initFbCommentsJS = {attrs ->
def settings = grailsApplication.config.grails.plugin?.facebookcomments

def appId
if(attrs.appId) {
appId = attrs.appId
} else {
appId = settings?.appId
}

if(!appId) {
throwTagError("Facebook appId is neither configured in config nor specified in tag")
}

out << render(template:"/templates/fb-comment/fb-comment-js", contextPath: pluginContextPath, model:[appId:appId])
}

private void addFbAttr(Map attrs, name, value) {
if(name && value) {
name = "data-"+name
attrs[name] = value
}
}
}
9 changes: 9 additions & 0 deletions grails-app/views/templates/fb-comment/_fb-comment-js.gsp
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<div id="fb-root"></div>
<script>(function(d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) return;
js = d.createElement(s); js.id = id;
js.src = "//connect.facebook.net/en_GB/all.js#xfbml=1&appId=${appId}";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
</script>

0 comments on commit 0b47377

Please sign in to comment.