JRuby on Roller
This is just a quick follow-up to my previous post on Pluggable renderers and scripting languages in Roller. It took me a while, but I finally made JRuby code work inside a Roller page template. Here's an example JRuby page template that displays most recent blog titles and text in HTML format.
Not the most beautiful thing in the world, I must admit. Any JRuby experts reading along? Is there a simple templating solution that will work in JRuby... something like Groovy Templates? And is there a way to map puts output to a java.io.Writer that will work via BSF?$out.println "<html><head>"
$out.println "<title>#{$model.weblog.name}</title>"
$out.println "</head><body>"
$out.println "<h1>#{$model.weblog.name}</h1>"
$model.weblogEntriesPager.entries.keySet().each {|day|
$model.weblogEntriesPager.entries.get(day).each {|entry|
$out.println "<h3>#{entry.title}</h3>"
$out.println "<p>#{entry.text}</p>"
}
}
$out.println "</body></html>"
Posted by Patrick Mueller on March 21, 2007 at 03:21 AM EDT #
As far as getting puts to go to a java.io.Writer, you could assign to $stdout an object that looks like a Ruby IO but forwards/delegates print/write calls to the Java Writer. Or you could construct the JRuby runtime outside of BSF and explicitly set the stdout stream to your writer -- see org.jruby.Ruby.newInstance(InputStream,PrintStream,PrintStream)
Posted by Nick Sieger on March 21, 2007 at 04:09 PM EDT #
Posted by Dave Johnson on March 21, 2007 at 05:03 PM EDT #
Posted by Charles Oliver Nutter on March 22, 2007 at 01:14 AM EDT #