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

前端 未结 7 1134
情深已故
情深已故 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:38

    Write a ruby script that does it. The API documentation is here: http://www.ruby-doc.org/stdlib/libdoc/erb/rdoc/

    For example:

    template = ERB.new File.read("path/to/template.erb"), nil, "%"
    template.result(binding)
    

    (Where binding is a binding with the @vars that the template needs.)

提交回复
热议问题