-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathMaprestGrailsPlugin.groovy
More file actions
39 lines (32 loc) · 1.32 KB
/
MaprestGrailsPlugin.groovy
File metadata and controls
39 lines (32 loc) · 1.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import com.jondejong.maprest.MaprestFormat
import com.jondejong.maprest.MaprestRenderer
class MaprestGrailsPlugin {
def version = "0.1.1"
def grailsVersion = "2.0 > *"
def loadAfter = ['controllers']
def observe = ["controllers"]
def title = "Maprest Plugin"
def author = "Jon DeJong"
def authorEmail = ""
def description = 'Allows customization of REST responses using property maps.'
def documentation = "https://github.com/jondejong/maprest"
def license = "APACHE"
def issueManagement = [ system: "Github", url: "https://github.com/jondejong/maprest/issues" ]
def scm = [url: "https://github.com/jondejong/maprest"]
def doWithDynamicMethods = { ctx ->
addMethodsToControllers(application)
}
def onChange = { event ->
addMethodsToControllers(application)
}
def addMethodsToControllers(application) {
MaprestRenderer renderer = new MaprestRenderer()
for (controllerClass in application.controllerClasses) {
controllerClass.metaClass.getXmlFormat = { MaprestFormat.XML }
controllerClass.metaClass.getJsonFormat = { MaprestFormat.JSON }
controllerClass.metaClass.renderMaprest = { Object o, MaprestFormat f, String root = null ->
renderer.renderMaprest o, f, root
}
}
}
}