jQuery Plugin

Configurable version of jquery

Details

  • Type: Improvement Improvement
  • Status: Resolved Resolved
  • Priority: Major Major
  • Resolution: Fixed
  • Affects Version/s: None
  • Fix Version/s: Grails-jQuery 1.4.2.1
  • Component/s: None
  • Labels:
    None

Description

It would be nice to make the used version of jquery configurable. Currently, the jquery version is hard coded in the JQueryConfig.groovy file. As a possible solution one could also parse the grails config during the initialization and use the configured value from there if available or fall back to the default as it is.

I currently use the jQuery plugin 1.4.1.1 but tweaked it to use jquery 1.3.2

Activity

Hide
David added a comment -

I would love to have this improvement.

I am not much into plugins structure, but this works:

JqueryGrailsPlugin.groovy, line 35
ConfigObject config =         new ConfigSlurper().parse(classLoader.loadClass('JQueryConfig'))
                       .merge(new ConfigSlurper().parse(classLoader.loadClass('Config')))
Config.groovy, your app config file
jquery {
    sources = 'jquery' // Holds the value where to store jQuery-js files /web-app/js/
    version = '1.4.2' // The jQuery version in use
}
Show
David added a comment - I would love to have this improvement. I am not much into plugins structure, but this works:
JqueryGrailsPlugin.groovy, line 35
ConfigObject config =         new ConfigSlurper().parse(classLoader.loadClass('JQueryConfig'))
                       .merge(new ConfigSlurper().parse(classLoader.loadClass('Config')))
Config.groovy, your app config file
jquery {
    sources = 'jquery' // Holds the value where to store jQuery-js files /web-app/js/
    version = '1.4.2' // The jQuery version in use
}
Hide
Finn Herpich added a comment -

Hey Guys,

I'm a little busy right now, but I hope my crunchtimes here will pass by so I can put out a new version with this feature.

Cheers

Show
Finn Herpich added a comment - Hey Guys, I'm a little busy right now, but I hope my crunchtimes here will pass by so I can put out a new version with this feature. Cheers
Hide
Ford Guo added a comment - - edited

if i develop a plugin depends on jquery,there are some exceptions when i pakcage-plugin:

org.codehaus.groovy.grails.exceptions.NewInstanceCreationException: Could not create a new instance of class [JqueryGrailsPlugin]!
at _PluginDependencies_groovy$_run_closure5_closure40.doCall(_PluginDependencies_groovy:269)
at _PluginDependencies_groovy$_run_closure5_closure40.doCall(_PluginDependencies_groovy)
at _GrailsSettings_groovy$_run_closure10.doCall(_GrailsSettings_groovy:282)
at _GrailsSettings_groovy$_run_closure10.call(_GrailsSettings_groovy)
at _PluginDependencies_groovy$_run_closure5.doCall(_PluginDependencies_groovy:267)
at _GrailsPackage_groovy$_run_closure2.doCall(_GrailsPackage_groovy:167)
at _GrailsPluginDev_groovy$_run_closure1.doCall(_GrailsPluginDev_groovy:58)
at gant.Gant$_dispatch_closure5.doCall(Gant.groovy:381)
at gant.Gant$_dispatch_closure7.doCall(Gant.groovy:415)
at gant.Gant$_dispatch_closure7.doCall(Gant.groovy)
at gant.Gant.withBuildListeners(Gant.groovy:427)
at gant.Gant.this$2$withBuildListeners(Gant.groovy)
at gant.Gant$this$2$withBuildListeners.callCurrent(Unknown Source)
at gant.Gant.dispatch(Gant.groovy:415)
at gant.Gant.this$2$dispatch(Gant.groovy)
at gant.Gant.invokeMethod(Gant.groovy)
at gant.Gant.executeTargets(Gant.groovy:590)
at gant.Gant.executeTargets(Gant.groovy:589)
Caused by: java.lang.ClassNotFoundException: Config
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
at JqueryGrailsPlugin.<init>(JqueryGrailsPlugin.groovy:37)
... 18 more

Show
Ford Guo added a comment - - edited if i develop a plugin depends on jquery,there are some exceptions when i pakcage-plugin: org.codehaus.groovy.grails.exceptions.NewInstanceCreationException: Could not create a new instance of class [JqueryGrailsPlugin]! at _PluginDependencies_groovy$_run_closure5_closure40.doCall(_PluginDependencies_groovy:269) at _PluginDependencies_groovy$_run_closure5_closure40.doCall(_PluginDependencies_groovy) at _GrailsSettings_groovy$_run_closure10.doCall(_GrailsSettings_groovy:282) at _GrailsSettings_groovy$_run_closure10.call(_GrailsSettings_groovy) at _PluginDependencies_groovy$_run_closure5.doCall(_PluginDependencies_groovy:267) at _GrailsPackage_groovy$_run_closure2.doCall(_GrailsPackage_groovy:167) at _GrailsPluginDev_groovy$_run_closure1.doCall(_GrailsPluginDev_groovy:58) at gant.Gant$_dispatch_closure5.doCall(Gant.groovy:381) at gant.Gant$_dispatch_closure7.doCall(Gant.groovy:415) at gant.Gant$_dispatch_closure7.doCall(Gant.groovy) at gant.Gant.withBuildListeners(Gant.groovy:427) at gant.Gant.this$2$withBuildListeners(Gant.groovy) at gant.Gant$this$2$withBuildListeners.callCurrent(Unknown Source) at gant.Gant.dispatch(Gant.groovy:415) at gant.Gant.this$2$dispatch(Gant.groovy) at gant.Gant.invokeMethod(Gant.groovy) at gant.Gant.executeTargets(Gant.groovy:590) at gant.Gant.executeTargets(Gant.groovy:589) Caused by: java.lang.ClassNotFoundException: Config at java.net.URLClassLoader$1.run(URLClassLoader.java:202) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:190) at java.lang.ClassLoader.loadClass(ClassLoader.java:307) at java.lang.ClassLoader.loadClass(ClassLoader.java:248) at JqueryGrailsPlugin.<init>(JqueryGrailsPlugin.groovy:37) ... 18 more
Hide
David added a comment - - edited

My fault
I don't know exactly what the problem is, it seems that the contruction of the attributes jQueryVersion and jQuerySources fails.
As you are using a modified version, can you try this?:

JqueryGrailsPlugin.groovy
/*
 * 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 {
	def version = "1.4.2.1"
	def dependsOn = [:]
	def author = "Sergey Nebolsin, Craig Jones and Finn Herpich"
	def authorEmail = "nebolsin@gmail.com, craigjones@maximsc.com and finn.herpich@marfinn-software.de"
	def title = "JQuery for Grails"
	def description = "Provides integration for the JQuery library with grails JavascriptProvider"
	def documentation = "http://grails.org/JQuery+Plugin"

	GroovyClassLoader classLoader = new GroovyClassLoader(getClass().getClassLoader())

    ConfigObject config
    
	def jQueryVersion
	def jQuerySources

	def doWithSpring = {
		jQueryConfig(JQueryConfig)
        
                // Applied GRAILSPLUGINS-2056
                def pluginConfig = classLoader.loadClass('JQueryConfig')
                def appConfig = classLoader.loadClass('Config')

                config = new ConfigSlurper().parse(pluginConfig)
                                            .merge(new ConfigSlurper().parse(appConfig))
                                
                jQueryVersion = config.jquery.version
                jQuerySources = config.jquery.sources
        
	}

	def doWithApplicationContext = {applicationContext ->
		if(GrailsUtil.environment == GrailsApplication.ENV_DEVELOPMENT) {
			JavascriptTagLib.LIBRARY_MAPPINGS.jquery = ["${jQuerySources}/jquery-${jQueryVersion}"]
		} else {
			JavascriptTagLib.LIBRARY_MAPPINGS.jquery = ["${jQuerySources}/jquery-${jQueryVersion}.min"]
		}

		def jQueryConfig = applicationContext.jQueryConfig
		jQueryConfig.init()

		if(jQueryConfig.defaultPlugins) {
			jQueryConfig.defaultPlugins.each { pluginName ->
				jQueryConfig.plugins."$pluginName".each {fileName ->
					JavascriptTagLib.LIBRARY_MAPPINGS.jquery += ["${jQuerySources}/${fileName}"[0..-4]]
				}
			}
		}

		JavascriptTagLib.PROVIDER_MAPPINGS.jquery = JQueryProvider.class
	}
}
Show
David added a comment - - edited My fault I don't know exactly what the problem is, it seems that the contruction of the attributes jQueryVersion and jQuerySources fails. As you are using a modified version, can you try this?:
JqueryGrailsPlugin.groovy
/*
 * 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 {
	def version = "1.4.2.1"
	def dependsOn = [:]
	def author = "Sergey Nebolsin, Craig Jones and Finn Herpich"
	def authorEmail = "nebolsin@gmail.com, craigjones@maximsc.com and finn.herpich@marfinn-software.de"
	def title = "JQuery for Grails"
	def description = "Provides integration for the JQuery library with grails JavascriptProvider"
	def documentation = "http://grails.org/JQuery+Plugin"

	GroovyClassLoader classLoader = new GroovyClassLoader(getClass().getClassLoader())

    ConfigObject config
    
	def jQueryVersion
	def jQuerySources

	def doWithSpring = {
		jQueryConfig(JQueryConfig)
        
                // Applied GRAILSPLUGINS-2056
                def pluginConfig = classLoader.loadClass('JQueryConfig')
                def appConfig = classLoader.loadClass('Config')

                config = new ConfigSlurper().parse(pluginConfig)
                                            .merge(new ConfigSlurper().parse(appConfig))
                                
                jQueryVersion = config.jquery.version
                jQuerySources = config.jquery.sources
        
	}

	def doWithApplicationContext = {applicationContext ->
		if(GrailsUtil.environment == GrailsApplication.ENV_DEVELOPMENT) {
			JavascriptTagLib.LIBRARY_MAPPINGS.jquery = ["${jQuerySources}/jquery-${jQueryVersion}"]
		} else {
			JavascriptTagLib.LIBRARY_MAPPINGS.jquery = ["${jQuerySources}/jquery-${jQueryVersion}.min"]
		}

		def jQueryConfig = applicationContext.jQueryConfig
		jQueryConfig.init()

		if(jQueryConfig.defaultPlugins) {
			jQueryConfig.defaultPlugins.each { pluginName ->
				jQueryConfig.plugins."$pluginName".each {fileName ->
					JavascriptTagLib.LIBRARY_MAPPINGS.jquery += ["${jQuerySources}/${fileName}"[0..-4]]
				}
			}
		}

		JavascriptTagLib.PROVIDER_MAPPINGS.jquery = JQueryProvider.class
	}
}

People

Vote (1)
Watch (1)

Dates

  • Created:
    Updated:
    Resolved: