RSS feed
<< Previous | Home | Next >>

adding Google Closure support to JPublish.

If you follow me on Twitter, you already know I started to re-write JPublish in Scala, tho it's a long way and it is mostly an experiment so far.

However, the existing JPublish version is enterprise ready but it lacks a nice AJAX/JS templating support. Tried jmaki, but I wasn't too happy about that. With the availability of the new Google's awesome Closure library, it is imperative for me to integrate JPublish with the Closure templates. I'll find a way to do that and will let you know here how it goes.

It will be a lot of fun!


extra 5 minutes of fun; JRuby and Velocity

As promised, this time I am showing you a very simple way to play with Velocity templating language in JRuby.

jvel.rb
# A simple JRuby Velocity integration demo 
# Notes:
# - save this script as 'jvel.rb'.
# - in the folder from where you're executing this simple script, you'll
# have a subfolder: 'lib', containing the Velocity library:
# lib/velocity-1.6.2-dep.jar
# This jar is intended to be used when you do standalone development
# with Velocity. And assuming that you have jruby in the path, you can
# run the script:
#
# $ jruby jvel.rb World
#
# You'll see: Hello World!
# -----------

require 'java'

Dir["lib/*.jar"].each { |jar| require jar }
 
class JRubyVelocity
include_class 'java.io.StringWriter'
include_class 'org.apache.velocity.app.Velocity'
include_class 'org.apache.velocity.VelocityContext'

def render
( arg)
Velocity.init
writer = StringWriter.new
ctx = VelocityContext.new( {'name' => arg})
Velocity.evaluate( ctx, writer, "log", "Hello ${name}!")
return writer.getBuffer
end
end

puts JRubyVelocity.new().render( ARGV.pop)

Good luck!

5 minutes of fun: JRuby and StringTemplate

If you like to explore some stuff on templating, and I highly recommend StringTemplate, this is how you can do it from JRuby.

jrst.rb

# A simple JRuby StringTemplate integration demo 
# Notes:
# - save this script as 'jrst.rb'.
# - in the folder from where you're executing this simple script, you'll
# have a subfolder: 'lib', containing the StringTemplate libraries:
# lib/antlr-2.7.7.jar
# lib/stringtemplate-3.2.1.jar
# run the script
# $ jruby jrst.rb World
#
# You'll see: Hello World!
# -----------
require 'java'

Dir["lib/*.jar"].each { |jar| require jar }

class JRubySringTemplate
include_class 'java.io.StringWriter'
include_class 'org.antlr.stringtemplate.StringTemplate'

def render ( arg)
st = StringTemplate.new("Hello $name$!")
st.set_attributes( {'name' => arg});
writer = StringWriter.new
writer.write( st.toString)
return writer.getBuffer
end
end

puts JRubySringTemplate.new().render( ARGV[0])

 

My 5 minutes of fun in a lunch break. Next time I'll show you how to use Velocity in the same way :)

Have fun!