Envjs is an implementation of the DOM in Javascript. Together with Rhino, it can function as a headless web browser in Java. Picture HtmlUnit, but with flawless Javascript support. For instance, the latest version of JQuery works flawlessly in Envjs on Rhino but won't even load in HtmlUnit.
Here's a simple way to tie them together in JUnit. Wonderful testing frameworks to follow (looking at you, Mike ;)
Not too many Groovy-isms here, can easily be converted to plain Java.
Thursday, August 5, 2010
Friday, July 23, 2010
Watch Directory For Changes in Groovy
One must-have feature in any modern web stack is the ability to automatically restart/refresh the development server when you edit the source code. It is critical for developer workflow that the feedback loop be as tight as possible. Here source code refers to actual class definitions, templates (JSPs, GSPs, haml files, etc...), static content (javascript, css, images), AND configuration (I'm looking at you, struts.xml).
All web frameworks which do not support automatic updating of all content during development shall hereafter be referred to as "Legacy Web Frameworks". Is your shop using them?
Justin Voss and I have been hard at work on a web micro-framework called Ratpack (inspired by Ruby's Sinatra). Lest it become a Legacy Web Framework right out of the gate, we've implemented basic auto-reloading right away. Feel free to grab this for other uses, as it works independently.
The script app/myapp.groovy will be killed and re-run when any content in the app directory changes.
Since Ratpack uses Jetty, there are probably better solutions. Feedback is welcome.
The NIO.2 Filesystem in JDK7 will make this sort of thing much easier.
All web frameworks which do not support automatic updating of all content during development shall hereafter be referred to as "Legacy Web Frameworks". Is your shop using them?
Justin Voss and I have been hard at work on a web micro-framework called Ratpack (inspired by Ruby's Sinatra). Lest it become a Legacy Web Framework right out of the gate, we've implemented basic auto-reloading right away. Feel free to grab this for other uses, as it works independently.
groovy runapp.groovy app/myapp.groovy app
The script app/myapp.groovy will be killed and re-run when any content in the app directory changes.
Since Ratpack uses Jetty, there are probably better solutions. Feedback is welcome.
The NIO.2 Filesystem in JDK7 will make this sort of thing much easier.
Sunday, May 9, 2010
Haml For Grails
Writing a Grails app? Find out why so many Rubyists swear by Haml for writing views.
Interested parties have created JHaml, a Java implementation of Haml, and a corresponding Grails plugin. (Patches welcome!)
To try it out, just grab the plugin:
Now, you have the option of writing views (with the .haml extension) that will be automatically rendered to GSPs.
Learn more in the Haml tutorial.
Official Grails Plugin Page
To try it out, just grab the plugin:
grails install-plugin hamlThen add this bean definition to your grails-app/conf/spring/resources.groovy.
Now, you have the option of writing views (with the .haml extension) that will be automatically rendered to GSPs.
Learn more in the Haml tutorial.
Official Grails Plugin Page
Sunday, April 18, 2010
"Holy Grail" Three-Column Layout in Haml and Sass
Thanks to Matthew Levine for his article In Search of the Holy Grail.
Feel free to post your own variants!
Feel free to post your own variants!
Monday, January 12, 2009
Beyond web.xml
Another day paying the bills in Eclipse...
So you've just written yourself a spiffy little servlet and you want to test it out. That's when it hits you... there is a long and arduous road ahead. You've got to remember how to deploy a War (how does that Ant script go again?). You need to configure Tomcat (Or wait 20 minutes for Weblogic to start). Then you need to write that dreaded web.xml file. This is a barren wasteland, riddled with fire and ash and dust. The very air you breathe is a poisonous fume. Not with ten thousand men could you do this. Tis folly!
Dag-nabbit! You aren't writing a big fancy industrial strength web app. All you want to do is run your little servlet in a local web browser and get on with your life! Jiminy Cricket, it's times like this that can turn a developer to Rails.
So what are you going to do? Bite the bullet and muddle through it all for the umpteenth time? Give up and write a command line app? Recall that the three chief virtues of a programmer are: Laziness, Impatience, and Hubris. Where there is a will, there is a way.
Grab yourself a Jetty jar and throw one of these in your app:
public class HelloWorldServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
resp.getWriter().println("Hello World!");
}
}So you've just written yourself a spiffy little servlet and you want to test it out. That's when it hits you... there is a long and arduous road ahead. You've got to remember how to deploy a War (how does that Ant script go again?). You need to configure Tomcat (Or wait 20 minutes for Weblogic to start). Then you need to write that dreaded web.xml file. This is a barren wasteland, riddled with fire and ash and dust. The very air you breathe is a poisonous fume. Not with ten thousand men could you do this. Tis folly!
Dag-nabbit! You aren't writing a big fancy industrial strength web app. All you want to do is run your little servlet in a local web browser and get on with your life! Jiminy Cricket, it's times like this that can turn a developer to Rails.
So what are you going to do? Bite the bullet and muddle through it all for the umpteenth time? Give up and write a command line app? Recall that the three chief virtues of a programmer are: Laziness, Impatience, and Hubris. Where there is a will, there is a way.
Grab yourself a Jetty jar and throw one of these in your app:
import org.mortbay.jetty.Server;Run it. Point your browser to http://localhost:8080/hello and you're good to go.
import org.mortbay.jetty.servlet.Context;
import org.mortbay.jetty.servlet.ServletHolder;
public class EmbeddedServletRunner {
public static void main(String[] args) throws Exception {
Server server = new Server(8080);
Context root = new Context(server,"/",Context.SESSIONS);
root.addServlet(new ServletHolder(new HelloWorldServlet()), "/hello");
server.start();
}
}
Sunday, October 26, 2008
Ladies and Gentlemen, The Editor War
Scene opens. The Lakota coffee shop in Columbia, MO.
Jane: ... and the other has been really interesting. It's Anthropology, with Jim Metcher.
Ray: (lights up) Yes! I actually got to take one of Metcher's classes during my brief stint in the evening program.
Jane: Are a Mizzou student?
Ray: Close. I graduated from MST in '06. I'm workin' now.
Jane: What do you do?
Ray: I help machines think. I'm a programmer.
Jane: Spiffy! So what's new in the fast-paced world of "programming"?
Ray: Well, lot's of things I guess. Let's see... new languages coming out as usual. PHP making some controversial design decisions regarding namespace. 50th anniversary of Lisp was just celebrated at OOPSLA; I bet there were some great talks at that. Oh yeah, and I just read about a new development in The Editor War.
Jane: ... The editor what?
Ray: War. The Editor War... it's this infamous feud. (waves hand dismissively)
Jane: Feud? (interest grows at the scent of scandal) Over what?
Ray: Which text editor to use.
Jane: (Smirk) No, really. What is it about? I'm actually interested this time, you don't have to make things up to amuse me.
Ray: No... (Slowly raises hand to forehead), that's actually what it's about.
Jane: (Confused) That doesn't sound like a very political decision. Is there some, like, protocol or something that has to... (pauses) I thought text was all sort of... compatible. (glances downward) I guess I don't much about this stuff.
Ray: Actually, you've got a decent grasp of it. While there have been a few new standards in recent years to accommodate different languages, text is overall very compatible from one editor to the next.
Jane: In that case, I don't get it. What other technical hurdle would force all programmers to use the same editor?
Ray: Ahh! I see the source of your confusion. That's not the issue. We're not debating the adoption of an official industry-wide standard editor. Nothing along those lines. It's a matter of personal preference.
Jane: (Disappointed) So it's just different people choosing a different tool? Aren't you exaggerating a bit by calling it a feud?
Ray: I see where you might think that, but believe it or not, I've been to parties where shouting matches broke out spontaneously at the mention of either of these editors.
Jane: Really?
Ray: Really.
Jane: Wow. So this has been going on for what, weeks now?
Ray: A bit longer than that.
Jane: Months?
Ray: It has been going on for over 25 years.
Jane: ... and the other has been really interesting. It's Anthropology, with Jim Metcher.
Ray: (lights up) Yes! I actually got to take one of Metcher's classes during my brief stint in the evening program.
Jane: Are a Mizzou student?
Ray: Close. I graduated from MST in '06. I'm workin' now.
Jane: What do you do?
Ray: I help machines think. I'm a programmer.
Jane: Spiffy! So what's new in the fast-paced world of "programming"?
Ray: Well, lot's of things I guess. Let's see... new languages coming out as usual. PHP making some controversial design decisions regarding namespace. 50th anniversary of Lisp was just celebrated at OOPSLA; I bet there were some great talks at that. Oh yeah, and I just read about a new development in The Editor War.
Jane: ... The editor what?
Ray: War. The Editor War... it's this infamous feud. (waves hand dismissively)
Jane: Feud? (interest grows at the scent of scandal) Over what?
Ray: Which text editor to use.
Jane: (Smirk) No, really. What is it about? I'm actually interested this time, you don't have to make things up to amuse me.
Ray: No... (Slowly raises hand to forehead), that's actually what it's about.
Jane: (Confused) That doesn't sound like a very political decision. Is there some, like, protocol or something that has to... (pauses) I thought text was all sort of... compatible. (glances downward) I guess I don't much about this stuff.
Ray: Actually, you've got a decent grasp of it. While there have been a few new standards in recent years to accommodate different languages, text is overall very compatible from one editor to the next.
Jane: In that case, I don't get it. What other technical hurdle would force all programmers to use the same editor?
Ray: Ahh! I see the source of your confusion. That's not the issue. We're not debating the adoption of an official industry-wide standard editor. Nothing along those lines. It's a matter of personal preference.
Jane: (Disappointed) So it's just different people choosing a different tool? Aren't you exaggerating a bit by calling it a feud?
Ray: I see where you might think that, but believe it or not, I've been to parties where shouting matches broke out spontaneously at the mention of either of these editors.
Jane: Really?
Ray: Really.
Jane: Wow. So this has been going on for what, weeks now?
Ray: A bit longer than that.
Jane: Months?
Ray: It has been going on for over 25 years.
Wednesday, July 16, 2008
Clone Wizards of Time and Space
The talk, Code Generation: The Safety Scissors Of Metaprogramming by Giles Bowkett.
The quote, "This is how Lisp guys think of Lisp and the Lisp community: intergalactic voluntarily bald clone wizards of time and space who the womens are be lusting fors."
He literally said that. I'm not paraphrasing. One more time in case you missed it.

I for one am quite offended! I resent the continuing perception that Lispers are smug and arrogant. Nothing could be further from the truth! We do not see ourselves as some sort of secret society with magic powers beyond the comprehension of you mere mortals.
Signed,
Ray, Squire of the Grand Recursive Order of the Knights of the Lambda Calculus
The quote, "This is how Lisp guys think of Lisp and the Lisp community: intergalactic voluntarily bald clone wizards of time and space who the womens are be lusting fors."
He literally said that. I'm not paraphrasing. One more time in case you missed it.

Intergalactic Voluntarily Bald Clone Wizards of Time and Space Who The Womens Are Be Lusting Fors.
I for one am quite offended! I resent the continuing perception that Lispers are smug and arrogant. Nothing could be further from the truth! We do not see ourselves as some sort of secret society with magic powers beyond the comprehension of you mere mortals.
Signed,
Ray, Squire of the Grand Recursive Order of the Knights of the Lambda Calculus
Subscribe to:
Comments (Atom)