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

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

    Found this question while trying to test my Puppet templates.

    Ended with this solution:

    1. Along your foo.erb create a file foo.vars.erb
    2. Put all your template variables into that new file, e.g.:

      <% @my_param="foo bar" %>
      <% @another_param=123 %>
      

      or (equivalent):

      <%
      @my_param="foo bar"
      @another_param=123
      %>
      
    3. On command line run this:

      cat foo.vars.erb foo.erb | erb
      

    Your fully rendered template should now be printed to std-out. From there you check the output by hand, or you can take diff (or other tools) to compare it to a pre-rendered output.

    0 讨论(0)
提交回复
热议问题