/
Sitemesh3GrailsPlugin.groovy
78 lines (63 loc) · 3.12 KB
/
Sitemesh3GrailsPlugin.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package org.sitemesh.grails.plugins.sitemesh3
import grails.plugins.Plugin
import org.grails.config.PropertySourcesConfig
import org.grails.web.gsp.io.GrailsConventionGroovyPageLocator
import org.grails.web.sitemesh.GroovyPageLayoutFinder
import org.springframework.core.env.ConfigurableEnvironment
import org.springframework.core.env.MapPropertySource
import org.springframework.core.env.PropertySource
class Sitemesh3GrailsPlugin extends Plugin {
def grailsVersion = "6.0.0 > *"
def pluginExcludes = [
"grails-app/views/error.gsp"
]
def title = "SiteMesh 3"
def author = "Scott Murphy"
def authorEmail = ""
def description = "Configures Grails to use SiteMesh 3 instead of SiteMesh 2"
def profiles = ['web']
def documentation = "https://github.com/codeconsole/grails-sitemesh3"
def license = "APACHE"
def organization = [name: "SiteMesh", url: "https://github.com/sitemesh"]
def developers = [[name: "Scott Murphy"]]
def issueManagement = [system: "GitHub", url: "https://github.com/codeconsole/grails-sitemesh3/issues"]
def scm = [url: "https://github.com/codeconsole/grails-sitemesh3"]
def loadBefore = ['groovyPages']
static PropertySource getDefaultPropertySource(ConfigurableEnvironment configurableEnvironment, String defaultLayout) {
Map props = [
'grails.gsp.view.layoutViewResolver': 'false',
'sitemesh.decorator.metaTag': 'layout',
'sitemesh.decorator.attribute': GroovyPageLayoutFinder.LAYOUT_ATTRIBUTE,
'sitemesh.decorator.prefix': '/layouts/',
'sitemesh.decorator.tagRuleBundles': ['org.sitemesh.content.tagrules.html.Sm2TagRuleBundle'],
'grails.views.gsp.sitemesh.preprocess': 'false'
]
if (defaultLayout) {
props['sitemesh.decorator.default'] = defaultLayout
}
// if property already exists, don't override
props.clone().each {
if (configurableEnvironment.getProperty(it.key)) {
props.remove(it.key)
}
}
return new MapPropertySource("sitemesh3Properties", props)
}
GrailsConventionGroovyPageLocator groovyPageLocator
Closure doWithSpring() {
{ ->
ConfigurableEnvironment configurableEnvironment = application.mainContext.environment
def propertySources = configurableEnvironment.getPropertySources()
// https://gsp.grails.org/latest/guide/layouts.html
// Default view should be application, but it is inefficient to add a rule for a page that may not exist.
propertySources.addFirst(getDefaultPropertySource(configurableEnvironment, grailsApplication.getConfig().get("grails.sitemesh.default.layout", null)))
application.config = new PropertySourcesConfig(propertySources)
grailsLayoutHandlerMapping(GrailsLayoutHandlerMapping)
}
}
void doWithApplicationContext() {}
void doWithDynamicMethods() {}
void onChange(Map<String, Object> event) {}
void onConfigChange(Map<String, Object> event) {}
void onShutdown(Map<String, Object> event) {}
}