I recently took it upon myself to implement a BBCode codec class for Groovy/Grails, and this is what I came up with.
class BBCodeCodec {
static map = [ '[b](.*?)[/b]':'<strong>$1</strong>',
'[i](.*?)[/i]':'<em>$1</em>',
'[url=(.*?)](.*?)[/url]':'<a href="$1" target="_blank">$2</a>',
'[url](.*?)[/url]':'<a href="$1">$1</a>' ]
static encode = { str ->
def result = str.replaceAll("< ","<");
result = result.replaceAll(">", ">");
map.each { key, value ->
def escapedKey = key.replaceAll('\\[','\\\\[').replaceAll('\\]','\\\\]')
result = result.replaceAll(escapedKey, value)
}
return result
}
}
It’s pretty basic and uses replaceAll to change your BBCodes to html. Anything that is already in html gets changes and the characters are converted to their ascii codes. That way you don’t have to worry about anyone messing with your site.
If you want to use this, save it as BBCodeCodec.groovy in your project grails-app/utils folder and when you want to print out something that is BBCode, you just use:
mystring?.encodeAsBBCode()
Continue reading →
So gimp contains a useful tool, the quick mask too which you can use to remove backgrounds real easily, so I’m going to show you how to use it right now. Just as a note, I’m using the 2.7-dev version, so it might look a little different (I’m using single window mode) but the features used in this tutorial are in gimp 2.6 as well.
First we’re going to start out with this picture:
Continue reading →
Since around grails 1.3ish, they have stopped autogenerating eclipse and netbeans project files because STS handles it itself. So what does that mean for people who start at the commandline and then want to go to STS? Well at first I figured it was going to make my life a whole lot harder, but with some searching I was able to find this gem:
grails integrate-with --eclipse
Just with that it will generate your eclipse project files. Now you can go to import -> existing project to workspace and import your project. Once the project is imported, you’ll probably still have some errors (I did) in which case I was able to solve them by adding my grails installation in the workspace settings. If you can’t seem to figure something out, leave a comment and I’ll try to help you.
Posted in Howto/Tutorial, Programming
|
Tagged 1.3, eclipse, grails, import, integrate, project, source, spring, sts, toolkit, with
|
By default, grails just gives users a multi-select box when dealing with to-Many relationships in views. It’s damn ugly and incredibly ineffective if an end user is dealing with tons of things to select from. After tolerating it for a while I completely gave up and decided to write my own replacement for it using autocomplete from the richui plugin and prototype which is included with grails.
So, the first thing you’re going to want to do is install the richui plugin, you can do this by running:
grails install-plugin richui
In the directory of your project.
Now, for the example that I’m going to use, there are two classes, Author and Book, an author hasMany Books. So that’s what we’re going to work with. I wrote a little TagLib that you can use, so I’m not going to explain that code, but I’ll show it to you below.
Continue reading →