Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reference for using ERB templates in a Java app (via JRuby)

Tags:

java

ruby

erb

jruby

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?

like image 258
Dana Avatar asked Aug 14 '11 00:08

Dana


1 Answers

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)
like image 178
Victor Rodrigues Avatar answered Nov 15 '22 13:11

Victor Rodrigues