Parse scripts, css, special files as GSP
Dependency :
compile ":gsp-arse:1.3"
Summary
Installation
Install it:
Then add a URL mapping to your projects UrlMappings.groovy file e.g.
You can change "resource" to whatever you like.Then change your references to point to that URL in your layouts/main.gsp, or any specific views like this:
grails install-plugin gsp-arse
"/resource/$path**"(controller: 'script', action: 'parse')<link rel="stylesheet" href="${resource(dir:'resource/css',file:'main.css')}" /> <script type="text/javascript" src="${resource(dir:'resource/js',file:'application.js')}?color=FA8DFF"> </script>
Description
GSParse
This plugin adds parsing of resource files (e.g. javascript, css) from the base path directory as GSP files so you can use tags and data binding. The primary motivation for this was providing a way to pass in relative paths to resources in Javascrip to access controllers for AJAX calls. For example you can do this in your Javascript:-$(function() {
$("#task").autocomplete('${g.createLink(controller: "task", action: "suggestTask")}', {
max: ${max},
width: 300
});
});body {
background: url('${g.resource(dir: "image", file: "thing.png")}');
color: #${color};
}"/resource/$path**"(controller: 'script', action: 'parse')<script type="text/javascript" src="resource/js/application.js"></script>
Important: Version 1.1 now supports grails.mime.file.extensions, which parses the file extensions from URLs. When enabled it takes the file extension and mime type from response.formate.g. resource/somewhere/application.blat?type=javascriptreturns mime type text/javascript"script/somewhere/myfile.blat?type=blat"returns mime type text/blatTo set a parameter just add it to the URL. For example to set the color for the CSS example above add ?color=FFF to the url.see http://nerderg.com/GSParse for more documentation.