开发者

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

开发者 https://www.devze.com 2023-03-28 03:48 出处:网络
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

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

精彩评论

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

关注公众号