开发者

Reference for using ERB templates in a Java app (via 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 differ开发者_运维百科ent 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)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜