Javascript URL Mappings
Dependency :
compile ":javascript-url-mappings:0.1.1"
Summary
Installation
grails install-plugin javascript-url-mappings
Description
A Grails plugin to provide client-side reverse URL mappings outside of GSP files.
Just put one taglib call in your layout and your static javascript files can make use of Grails' UrlMappingsMore usage examples can be found in the javascript unit tests:
http://github.com/danklynn/grails-javascript-url-mappings/blob/0.1/grails-app/views/index.gsp
Example usage (jQuery)
<!-- Place this tag in your layout's head element: --> <g:urlMappings /> <script type="text/javascript"> var url = g.createLink({controller: 'news', action: 'fetch', params: {since: new Date()}}); $('#myDiv').load(url); var img = document.createElement('img'); img.src = g.resource({dir: 'images', file: 'icon.gif'}); </script>
Current Status
Currently reverse-maps all controllers and actions, using the paramscontroller , action , and optionally id . Supports building static resource URLs through use of the g.resource() function, using the params dir and file just like the built-in Grails taglib.Recent Changes
- 0.1.1 - Bugfix release, fixed bad template path
- 0.1 - initial release
TODOs
- Get project under jvm-level test
- Get project under functional test to test javascript from "grails test-app"
- Add support for named mappings
- Add support for mapping wildcards to reverse-map params (e.g. "controller/action?/id?")
- Support the "url" attribute of createLink
- Support absolute urls
Contributors
- Dan Lynn - http://github.com/danklynn/