Skip to content

Instantly share code, notes, and snippets.

@sheehan
Created December 3, 2012 23:19
Show Gist options
  • Save sheehan/4199012 to your computer and use it in GitHub Desktop.
Save sheehan/4199012 to your computer and use it in GitHub Desktop.
modules = {
core {
defaultBundle 'core'
dependsOn 'jquery, handlebars_runtime'
resource url: '/js/app/core/loader.coffee', bundle: 'core'
resource url: '/js/app/core/main.coffee', bundle: 'core'
resource url: '/css/app/core/mixins.less'
resource url: '/css/app/core/layout.less'
resource url: '/css/app/dummy.css'
}
book {
dependsOn 'core'
defaultBundle 'book'
resource url: '/templates/book/edit/form.hbs', attrs: [type: 'js'], bundle: 'book'
resource url: '/templates/book/edit/menu.hbs', attrs: [type: 'js'], bundle: 'book'
resource url: '/templates/book/edit/page.hbs', attrs: [type: 'js'], bundle: 'book'
resource url: '/templates/book/edit/toolbar.hbs', attrs: [type: 'js'], bundle: 'book'
resource url: '/templates/book/list/list.hbs', attrs: [type: 'js'], bundle: 'book'
resource url: '/templates/book/list/menu.hbs', attrs: [type: 'js'], bundle: 'book'
resource url: '/templates/book/list/page.hbs', attrs: [type: 'js'], bundle: 'book'
resource url: '/templates/book/list/toolbar.hbs', attrs: [type: 'js'], bundle: 'book'
resource url: '/templates/book/show/show.hbs', attrs: [type: 'js'], bundle: 'book'
resource url: '/templates/book/show/menu.hbs', attrs: [type: 'js'], bundle: 'book'
resource url: '/templates/book/show/page.hbs', attrs: [type: 'js'], bundle: 'book'
resource url: '/templates/book/show/toolbar.hbs', attrs: [type: 'js'], bundle: 'book'
resource url: '/js/app/book/edit.coffee', bundle: 'book'
resource url: '/js/app/book/list.coffee', bundle: 'book'
resource url: '/js/app/book/show.coffee', bundle: 'book'
resource url: '/css/app/book/book.less'
resource url: '/css/app/dummy.css'
}
author {
dependsOn 'core'
defaultBundle 'author'
resource url: '/templates/author/edit/form.hbs', attrs: [type: 'js'], bundle: 'author'
resource url: '/templates/author/edit/menu.hbs', attrs: [type: 'js'], bundle: 'author'
resource url: '/templates/author/edit/page.hbs', attrs: [type: 'js'], bundle: 'author'
resource url: '/templates/author/edit/toolbar.hbs', attrs: [type: 'js'], bundle: 'author'
resource url: '/templates/author/list/list.hbs', attrs: [type: 'js'], bundle: 'author'
resource url: '/templates/author/list/menu.hbs', attrs: [type: 'js'], bundle: 'author'
resource url: '/templates/author/list/page.hbs', attrs: [type: 'js'], bundle: 'author'
resource url: '/templates/author/list/toolbar.hbs', attrs: [type: 'js'], bundle: 'author'
resource url: '/templates/author/show/show.hbs', attrs: [type: 'js'], bundle: 'author'
resource url: '/templates/author/show/menu.hbs', attrs: [type: 'js'], bundle: 'author'
resource url: '/templates/author/show/page.hbs', attrs: [type: 'js'], bundle: 'author'
resource url: '/templates/author/show/toolbar.hbs', attrs: [type: 'js'], bundle: 'author'
resource url: '/js/app/author/edit.coffee', bundle: 'author'
resource url: '/js/app/author/list.coffee', bundle: 'author'
resource url: '/js/app/author/show.coffee', bundle: 'author'
resource url: '/css/app/author/author.less'
resource url: '/css/app/dummy.css'
}
publisher {
dependsOn 'core'
defaultBundle 'publisher'
resource url: '/templates/publisher/edit/form.hbs', attrs: [type: 'js'], bundle: 'publisher'
resource url: '/templates/publisher/edit/menu.hbs', attrs: [type: 'js'], bundle: 'publisher'
resource url: '/templates/publisher/edit/page.hbs', attrs: [type: 'js'], bundle: 'publisher'
resource url: '/templates/publisher/edit/toolbar.hbs', attrs: [type: 'js'], bundle: 'publisher'
resource url: '/templates/publisher/list/list.hbs', attrs: [type: 'js'], bundle: 'publisher'
resource url: '/templates/publisher/list/menu.hbs', attrs: [type: 'js'], bundle: 'publisher'
resource url: '/templates/publisher/list/page.hbs', attrs: [type: 'js'], bundle: 'publisher'
resource url: '/templates/publisher/list/toolbar.hbs', attrs: [type: 'js'], bundle: 'publisher'
resource url: '/templates/publisher/show/show.hbs', attrs: [type: 'js'], bundle: 'publisher'
resource url: '/templates/publisher/show/menu.hbs', attrs: [type: 'js'], bundle: 'publisher'
resource url: '/templates/publisher/show/page.hbs', attrs: [type: 'js'], bundle: 'publisher'
resource url: '/templates/publisher/show/toolbar.hbs', attrs: [type: 'js'], bundle: 'publisher'
resource url: '/js/app/publisher/edit.coffee', bundle: 'publisher'
resource url: '/js/app/publisher/list.coffee', bundle: 'publisher'
resource url: '/js/app/publisher/show.coffee', bundle: 'publisher'
resource url: '/css/app/publisher/publisher.less'
resource url: '/css/app/dummy.css'
}
}
Set fileSet(Map attr) {
String dir = attr.dir
String includes = attr.includes ?: '**/*'
Set matches = []
ServletContext servletContext = Holders.servletContext
if (servletContext) {
String basePath = servletContext.getRealPath(dir)
File baseDir = new File(basePath)
if (baseDir.exists()) {
AntPathMatcher antPathMatcher = new AntPathMatcher()
baseDir.eachFileRecurse(FileType.FILES) { File file ->
String path = file.path.replace(basePath, '')
path = path.replaceAll('\\\\', '/')
path = path[1..-1]
if (antPathMatcher.match(includes, path)) {
matches << "$dir/$path"
}
}
}
}
matches
}
import static com.example.ResourcesPluginUtil.fileSet
modules = {
core {
defaultBundle 'core'
dependsOn 'jquery, handlebars_runtime'
resource url: '/css/app/core/mixins.less'
resource url: '/css/app/core/layout.less'
resource url: '/js/app/core/loader.coffee', bundle: 'core'
resource url: '/js/app/core/main.coffee', bundle: 'core'
resource url: '/css/app/dummy.css'
}
book {
dependsOn 'core'
defaultBundle 'book'
fileSet(dir: '/templates/book', includes: '**/*.hbs').each { resource url: it, attrs: [type: 'js'], bundle: 'book' }
fileSet(dir: '/js/app/book', includes: '**/*.coffee').each { resource url: it, bundle: 'book' }
fileSet(dir: '/css/app/book', includes: '**/*.less').each { resource url: it }
resource url: '/css/app/dummy.css'
}
author {
dependsOn 'core'
defaultBundle 'author'
fileSet(dir: '/templates/author', includes: '**/*.hbs').each { resource url: it, attrs: [type: 'js'], bundle: 'author' }
fileSet(dir: '/js/app/author', includes: '**/*.coffee').each { resource url: it, bundle: 'author' }
fileSet(dir: '/css/app/author', includes: '**/*.less').each { resource url: it }
resource url: '/css/app/dummy.css'
}
publisher {
dependsOn 'core'
defaultBundle 'publisher'
fileSet(dir: '/templates/publisher', includes: '**/*.hbs').each { resource url: it, attrs: [type: 'js'], bundle: 'publisher' }
fileSet(dir: '/js/app/publisher', includes: '**/*.coffee').each { resource url: it, bundle: 'publisher' }
fileSet(dir: '/css/app/publisher', includes: '**/*.less').each { resource url: it }
resource url: '/css/app/dummy.css'
}
}
def module = { String name ->
"$name" {
dependsOn 'core'
defaultBundle name
fileSet(dir: "/templates/$name", includes: '**/*.hbs').each { resource url: it, attrs: [type: 'js'], bundle: name }
fileSet(dir: "/js/app/$name", includes: '**/*.coffee').each { resource url: it, bundle: name }
fileSet(dir: "/css/app/$name", includes: '**/*.less').each { resource url: it }
resource url: '/css/app/dummy.css'
}
}
import static com.example.ResourcesPluginUtil.fileSet
modules = {
core {
defaultBundle 'core'
dependsOn 'jquery, handlebars_runtime'
resource url: '/css/app/core/mixins.less'
resource url: '/css/app/core/layout.less'
resource url: '/js/app/core/loader.coffee', bundle: 'core'
resource url: '/js/app/core/main.coffee', bundle: 'core'
resource url: '/css/app/dummy.css'
}
def module = { String name ->
"$name" {
dependsOn 'core'
defaultBundle name
fileSet(dir: "/templates/$name", includes: '**/*.hbs').each { resource url: it, attrs: [type: 'js'], bundle: name }
fileSet(dir: "/js/app/$name", includes: '**/*.coffee').each { resource url: it, bundle: name }
fileSet(dir: "/css/app/$name", includes: '**/*.less').each { resource url: it }
resource url: '/css/app/dummy.css'
}
}
module 'book'
module 'author'
module 'publisher'
}
class BootStrap {
def grailsApplication
def pluginManager
def init = { ServletContext servletContext ->
if (Environment.isDevelopmentMode()) {
def resourcesPlugin = pluginManager.getGrailsPlugin('resources').@plugin
def watcher = new DirectoryWatcher()
def listener = new DirectoryWatcher.FileChangeListener() {
void onChange(File file) {}
void onNew(File file) {
resourcesPlugin.triggerReload {
grailsApplication.mainContext.grailsResourceProcessor.reloadModules()
}
}
}
watcher.addListener(listener)
['/css', '/js', '/templates'].each { String path ->
File dir = new File(servletContext.getRealPath(path))
watcher.addWatchDirectory(dir, '*')
}
watcher.start()
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment