Skip to content

Instantly share code, notes, and snippets.

@lesiki
Created January 30, 2013 10:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lesiki/4672312 to your computer and use it in GitHub Desktop.
Save lesiki/4672312 to your computer and use it in GitHub Desktop.
Grails Resources setup that automatically adds all resources in a folder
import org.codehaus.groovy.grails.web.context.ServletContextHolder as SCH
modules = {
core {
resource url: '/resources/css/app.css', disposition: 'head'
resource url: '/resources/css/myapp.css', disposition: 'head'
resource url: '/extjs/ext-all-debug.js', dispostion: 'head'
getFilesForPath('/app').each {
resource url: it
}
}
}
def getFilesForPath(path) {
def webFileCachePaths = []
def servletContext = SCH.getServletContext()
//context isn't present when testing in integration mode. -jg
if(!servletContext) return webFileCachePaths
def realPath = servletContext.getRealPath('/')
def appDir = new File("$realPath/$path")
appDir.eachFileRecurse {File file ->
if (file.isDirectory()) return
webFileCachePaths << file.path.replace(realPath, '')
}
webFileCachePaths
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment