Grails: How do I reference a resource located inside an installed plugin?

I have a Grails plugin in which I use as a main container for some common static resources that will be used by various other Grails own projects (CSS, JS files, etc.). The idea of โ€‹โ€‹using the plugin was to share these things - the plugin really does nothing interesting. What is the best way to directly reference resources inside a plugin? I'd rather not create custom taglibs, since Im really doesn't add any function here; I just need access to resources inside the plugin - something like this, for example, to link to a CSS file from GSP:

<g:link rel="stylesheet" url="${resource(dir:'css', file:'mycss.css', plugin:'myplugin')}"/> 

Does this idea violate the concept of plugins, where only some of its aspects should be disclosed, and the rest is a black box? Alternative approaches to the exchange of static resources between their related Grails projects are also welcome if Im leads the crazy, erroneous path, even by trying this. :)

+6
plugins resources grails
source share
1 answer

Firstly, in Grails, a plugin is not considered a black box. On the contrary, all code is open; if you really want to make it a black box, then you should use another plugin, Binary artifacts .

Secondly, your approach is very reasonable. To access the resources of the plugin, I would create a taglib like:

 def res = { attrs -> attrs.dir=pluginContextPath //Do whatever you want here out << g.resource(attrs) } 

and name it the same as <g:resource> . This way, you donโ€™t even have to set the resource path of your plugins. The agile plugin uses this approach.

You can also take a look at the Grails Resources plugin , which tries to deal with the nightmare of static resource dependencies among Grails plugins and projects. I never used it, but Iโ€™ll probably integrate it in my next Grails project (BTW, it will be included in Grails 1.4).

+3
source share

All Articles