-
Notifications
You must be signed in to change notification settings - Fork 29
/
Copy pathJqueryGrailsPlugin.groovy
executable file
·92 lines (76 loc) · 3.44 KB
/
JqueryGrailsPlugin.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
/*
* Copyright 2007-2009 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import grails.util.GrailsUtil;
import org.codehaus.groovy.grails.commons.GrailsApplication;
import org.codehaus.groovy.grails.plugins.web.taglib.*
import org.codehaus.groovy.grails.plugins.jquery.JQueryConfig
import org.codehaus.groovy.grails.plugins.jquery.JQueryProvider
import org.codehaus.groovy.grails.commons.ConfigurationHolder
class JqueryGrailsPlugin {
// Only change the point release. Edit o.c.g.g.o.j.JQueryConfig.SHIPPED_VERSION when changing jQuery resource version
def version = JQueryConfig.SHIPPED_VERSION
static SHIPPED_SRC_DIR = 'jquery'
// the version or versions of Grails the plugin is designed for
def grailsVersion = "1.2.2 > *"
def dependsOn = [:]
def pluginExcludes = [
"web-app/css",
"web-app/images",
"web-app/js/prototype",
"web-app/js/application.js"
]
def author = "Sergey Nebolsin, Craig Jone, Marc Palmer and Finn Herpich"
def title = "JQuery for Grails"
def description = "Provides integration for the JQuery library with grails JavascriptProvider"
def documentation = "http://grails.org/JQuery+Plugin"
static jQueryVersion
static jQuerySources
def doWithSpring = {
jQueryConfig(JQueryConfig)
}
void loadConfig() {
GroovyClassLoader classLoader = new GroovyClassLoader(getClass().getClassLoader())
def confClass
try {
confClass = classLoader.loadClass('JQueryConfig')
} catch (Exception e) {
// <gulp>
}
ConfigObject config = confClass ? new ConfigSlurper().parse(confClass).merge(ConfigurationHolder.config) : ConfigurationHolder.config
JqueryGrailsPlugin.jQueryVersion = config.jquery.version instanceof String ? config.jquery.version : JQueryConfig.SHIPPED_VERSION
JqueryGrailsPlugin.jQuerySources = config.jquery.sources instanceof String ? config.jquery.sources : JqueryGrailsPlugin.SHIPPED_SRC_DIR
}
def doWithApplicationContext = { applicationContext ->
// We need to init our own config first
loadConfig()
if(GrailsUtil.environment == GrailsApplication.ENV_DEVELOPMENT) {
JavascriptTagLib.LIBRARY_MAPPINGS.jquery = ["${JqueryGrailsPlugin.jQuerySources}/jquery-${JqueryGrailsPlugin.jQueryVersion}"]
} else {
JavascriptTagLib.LIBRARY_MAPPINGS.jquery = ["${JqueryGrailsPlugin.jQuerySources}/jquery-${JqueryGrailsPlugin.jQueryVersion}.min"]
}
def jQueryConfig = applicationContext.jQueryConfig
jQueryConfig.init()
if(jQueryConfig.defaultPlugins) {
jQueryConfig.defaultPlugins.each { pluginName ->
jQueryConfig.plugins."$pluginName".each {fileName ->
JavascriptTagLib.LIBRARY_MAPPINGS.jquery += ["${JqueryGrailsPlugin.jQuerySources}/${fileName}"[0..-4]]
}
}
}
JavascriptTagLib.PROVIDER_MAPPINGS.jquery = JQueryProvider.class
}
}