Skip to content

Instantly share code, notes, and snippets.

@erichelgeson
Last active November 19, 2015 14:40
Show Gist options
  • Save erichelgeson/ce1ec05b8688b619e1f4 to your computer and use it in GitHub Desktop.
Save erichelgeson/ce1ec05b8688b619e1f4 to your computer and use it in GitHub Desktop.
// Taglib for Grails to create a <g:routes/> tag to allow you to output all the data you'd need to
// emulate ${createLink} in JS
// eg: $.get(baseURL + CONTROLLER_ACTION) http://localhost:8080/app/CONTROLLER/ACTION
// eg: $.get(baseURL + BOOKS_LIST) == http://localhost:8080/app/books/list
def grailsLinkGenerator
def routes = {
out << '<script type="text/javascript">'
out << "var baseUrl = '//' + window.location.host + '${request.contextPath}';"
grailsApplication.controllerClasses.each {
if(it.clazz.name.startsWith("sproutary")) {
it.getURIs().each { uri ->
out << "var ${it.logicalPropertyName.toUpperCase()}_${it.getMethodActionName(uri).toUpperCase()} = '/${it.logicalPropertyName}/${it.getMethodActionName(uri)}';"
}
}
}
out << '</script>'
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment