forked from joergrech/KickstartWithBootstrap
-
Notifications
You must be signed in to change notification settings - Fork 0
/
KickstartWithBootstrapGrailsPlugin.groovy
105 lines (97 loc) · 4.39 KB
/
KickstartWithBootstrapGrailsPlugin.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
import org.codehaus.groovy.grails.commons.ApplicationHolder
import org.codehaus.groovy.grails.plugins.GrailsPluginUtils
import org.codehaus.groovy.grails.plugins.PluginManagerHolder
import org.codehaus.groovy.grails.web.context.ServletContextHolder
class KickstartWithBootstrapGrailsPlugin {
// the plugin version
def version = "0.9.2"
// the version or versions of Grails the plugin is designed for
def grailsVersion = "2.0 > *"
// the other plugins this plugin depends on
def dependsOn = [:]
// resources that are excluded from plugin packaging
def pluginExcludes = [
// "grails-app/views/error.gsp"
]
def license = "APACHE"
// def organization = [ name: "SpringSource", url: "http://www.springsource.org/" ]
// def developers = [
// [ name: "Jörg Rech", email: "[email protected]" ]
// ]
// def issueManagement = [ system: "JIRA", url: "http://jira.grails.org/browse/GRAILSPLUGINS" ]
def scm = [ url: "https://github.com/joergrech/KickstartWithBootstrap" ]
// TODO Fill in these fields
def author = "Joerg Rech"
def authorEmail = "[email protected]"
def title = "Kickstart with Bootstrap - Good looking websites!"
def description = "Kickstart is a plugin for Grails to start your project with a good looking frontend. It provides adapted scaffolding templates for standard CRUD pages using the Bootstrap web page template by Twitter."
// URL to the plugin's documentation
def documentation = "http://grails.org/plugin/kickstart-with-bootstrap"
// def doWithWebDescriptor = { xml ->
// // TODO Implement additions to web.xml (optional), this event occurs before
// }
//
// def doWithSpring = {
// // TODO Implement runtime spring config (optional)
// }
//
// def doWithDynamicMethods = { ctx ->
// // TODO Implement registering dynamic methods to classes (optional)
// }
//
def doWithApplicationContext = { applicationContext ->
// TODO Implement post initialization spring config (optional)
// Collect all *.properties files in the I18N directory and build list of "available" locales
def locales = []
def i18nDir
try {
if (ApplicationHolder.application.isWarDeployed()) {
def filePath = "grails-app/i18n"
i18nDir = ApplicationHolder.application.parentContext.getResource("${File.separator}WEB-INF${File.separator}${filePath}")?.getFile()
} else {
i18nDir = new File(System.properties['base.dir'] + "/grails-app/i18n")
}
if (i18nDir != null && i18nDir.exists()) {
i18nDir.eachFileRecurse {
if (it.file && it =~ /messages.*\.properties/) {
// Extract locale from filename using RegEx
def matcher = it.name =~ /messages(.*)\.properties/
def result = matcher[0][1] // @see http://groovy.codehaus.org/Regular+Expressions
if (result != null && result.size() == 3) {
locales << result.substring(1, 3).toLowerCase() // should be empty ("") and starts with "_" (e.g., "_de")
} else if (result != null && result.size() == 6) {
locales << result.substring(4, 6).toLowerCase() // should be empty ("") and starts with country (e.g., "_en_US")
} else {
// executed if the default "locale" - messages.properties is found
}
}
}
} else {
// add a minimum of locales
locales << "en"
locales << "de"
}
println "| Kickstart found ${locales.size()} locales usable in the language selector (excluding the default \"locale\" messages.properties)."
} catch (Exception e) {
log.warn "WARNING: could not find the directory to the project's I18N files! The Language Switcher might not work correctly!"
log.warn e.getMessage()
// add a minimum of locales
locales << "en"
locales << "de"
}
// Note: The GrailsApplication instance is available in all of the lifecycle closures as the "application" variable.
application.config.grails.i18n.locales = locales
System.setProperty('grails.i18n.locales', locales.toString())
}
//
// def onChange = { event ->
// // TODO Implement code that is executed when any artefact that this plugin is
// // watching is modified and reloaded. The event contains: event.source,
// // event.application, event.manager, event.ctx, and event.plugin.
// }
//
// def onConfigChange = { event ->
// // TODO Implement code that is executed when the project configuration changes.
// // The event is the same as for 'onChange'.
// }
}