-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathNavigationGrailsPlugin.groovy
62 lines (50 loc) · 1.88 KB
/
NavigationGrailsPlugin.groovy
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
class NavigationGrailsPlugin {
def version = '1.2'
// the version or versions of Grails the plugin is designed for
def grailsVersion = "1.2 > *"
def dependsOn = [controllers:"1.0 > *"]
def observe = ['controllers']
def loadAfter = ['logging']
def author = "Marc Palmer"
def authorEmail = "[email protected]"
def title = "Site Menu Navigation"
def description = '''\
Tags for doing site navigation and menus by convention
'''
def documentation = "http://grails.org/Navigation+Plugin"
def doWithSpring = {
// TODO Implement runtime spring config (optional)
}
def doWithApplicationContext = { applicationContext ->
}
def doWithWebDescriptor = { xml ->
// TODO Implement additions to web.xml (optional)
}
def doWithDynamicMethods = { ctx ->
refreshNavigation(application, applicationContext)
}
def onChange = { event ->
if (event.source instanceof Class) {
refreshNavigation(application, applicationContext)
}
}
private refreshNavigation(application, applicationContext) {
def navSrv = applicationContext.navigationService
navSrv.reset()
application.controllerClasses.each { controllerClass ->
// If there is a navigation property that is not null or false, we include it
def nav = false
if (controllerClass.clazz.metaClass.hasProperty(controllerClass.clazz, 'navigation')) {
nav = controllerClass.clazz.navigation
}
if (nav) {
navSrv.registerItem(controllerClass)
}
}
navSrv.update()
}
def onConfigChange = { event ->
// TODO Implement code that is executed when the project configuration changes.
// The event is the same as for 'onChange'.
}
}