I am trying to write a grails plugin to allow grails apps to scan qr codes. I'm using jsqrcode https://github.com/LazarSoft/jsqrcode to perform the actual interpretation of the qr codes.
This means that I need to include a number of javascript files in any page that uses my qrcode scanning tag.
Right now, I've created a tag that just imports the scripts and looks like:
StringBuilder sb = new StringBuilder()
sb << """<script src="/${grails.util.Metadata.current.'app.name'}/js/jsqrcode/grid.js"></script>"""
...
sb.toString()
This feels klugey to me.
Is there a better (right?) way to go about this?
To clarify, creating a tag to import specific javascript feels like a kludge for at least two reasons. First this requires that the person using the plugin must include this 'import' tag exactly once in any page using this library (I'm not a fan of unobvious dependency). And second, I'm concerned that the use of
${grails.util.Metadata.current.'app.name'}
could cause problems for people that use url mappings.
For dealing with JS includes it would be best to tie into the Grails Asset Pipeline plugin which is becoming a default plugin in grails 2.4 That plugin already has ways of making sure files are only included once, check out the documentation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With