RSS feed
<< James Strachan's favorite Mac applications | Home | StringTemplate for JPublish >>

JRuby actions in JPublish

As some of you already know, JPublish can execute actions written in JRuby. This is all possible through the magic of the BSF :)

I received a lot of questions about how can a JRuby Action use the java objects available in the JPublishContext?

There's nothing simpler than that, in JPublish is easy :) Below is the body of a JRuby Action which will print a message to the designated console log and will populate the page context with the variable "hello". The variable "hello" will be accessible to Velocity or Freemarker during the post action execution rendering process.

HelloJRuby.rb

require 'java'
$syslog.info("
HelloJRuby.rb action ...")
$context.put("hello", "Hello World!")

Simple, eh? Use the dollar sign in front of the variables you expect to find in the context.

Also, there is a recent web site with a lot of JRuby news and tips, check it out in case you're interested. Is called JRuby Inside.

Cheers!



Add a comment Send a TrackBack