如何在非rails应用程序中实现erb partials?

blu*_*ray 9 ruby erb partials

我想做这样的事情:

require 'erb'
@var = 'test'
template = ERB.new File.new("template.erb").read
rendered = template.result(binding())
Run Code Online (Sandbox Code Playgroud)

但是如何在template.erb中使用partials?

Ree*_*erg 8

也许蛮力呢?

header_partial = ERB.new(File.new("header_partial.erb").read).result(binding)
footer_partial = ERB.new(File.new("footer_partial.erb").read).result(binding)

template = ERB.new <<-EOF
  <%= header_partial %>
  Body content...
  <%= footer_partial %>
EOF
puts template.result(binding)
Run Code Online (Sandbox Code Playgroud)