Contribution Overview
GFreeMarker is
| Excerpt |
|---|
an integration of the FreeMarker template engine for Groovy |
Team Members
Cedric Champeau <cedric dot champeau at lingway dot com>
Download
Distributions
Installing
Pending.
Pre-requisites
None.
Documentation
How does it work ?
Imagine your customer requires an URL Encoding text transform, and that FreeMarker does not offer this transformation. Then, you would just need to :
- Create a plugin named urlencoder that implements the IGroovyFreeMarkerPlugin interface
- Copy this plugin into the Groovy FreeMarker template engine plugins directory
That's all ! Now your customer can access it quite directly in the template. For example :
| Code Block | ||
|---|---|---|
| ||
<@groovy plugin="urlencoder">this is an expression that will be converted to its URL Encoding form</@groovy> |
Writing a plugin
Here's a sample plugin which converts a string through URL encoder :
| Code Block |
|---|
import org.codehaus.groovy.gfreemarker.IGroovyFreeMarkerPlugin
class urlencoder implements IGroovyFreeMarkerPlugin {
String transform(Map params, String content) {
URLEncoder.encode(content);
}
}
|
Using the template engine
Here's a sample code which shows how easy it is to embed FreeMarker as a template engine for Groovy.
| Code Block |
|---|
import org.codehaus.groovy.gfreemarker.FreeMarkerTemplateEngine
def tpl = '''
Hello, ${user.name}
<@groovy plugin="urlencoder" mode=user>this is a test ${user.name}</@groovy>'''
def engine = new FreeMarkerTemplateEngine("plugins")
def binding = ["user" : ["name":"cedric"]]
println engine.createTemplate(tpl).make(binding)
|
This code assumes a directory called plugins is in the working directory. The template engine will dynamically load the ''urlencoder'' class.
Developers
Source Control
http://svn.codehaus.org/groovy-contrib/gfreemarker/trunk/
Building
GFreeMarker uses Maven2 as its build tool. Follow the instructions at http://maven.apache.org or install an IDE which has Maven 2 support (I personally use IntelliJ IDEA 7).
Contributing
Feel free to contribute, as I don't have much time to spend on this project.
Community
Mailing List(s)
http://groovy.codehaus.org/Mailing+Lists
Issue tracker
N/A