I have a legacy Ruby command line tool that uses (user supplied) ERB templates to format data. I am required to rewrite this tool in Java but I need to avoid having everyone rewrite their ERB templates in a different template language.
I think I can do this with embedded JRuby but I have never used it.
Are there any good examples or reference for using ERB from Java apps?
Here you can see at listing 6 how to call ruby from java with jruby.
And to use ERB is very easy :D
require 'erb'
# `binding` returns all variables declared in
# this scope, so they can be used in templates
#
ERB.new(File.read('file/path')).result(binding)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With