How do I execute ruby template files (ERB) without a web server from command line?

前端 未结 7 1149
情深已故
情深已故 2020-12-13 09:27

I need ERB (Ruby\'s templating system) for templating of non-HTML files.
(Instead, I want to use it for source files such as .java, .cs, ...)

7条回答
  •  一个人的身影
    2020-12-13 09:28

    If you can switch ERB to Erubis, your problem solving is as simple as:

    require 'erubis'
    template = File.read("sample_file.erb")
    template = Erubis::Eruby.new(template)
    template.result(:your_variable => "sample")
    

提交回复
热议问题