我正在寻找一种在 thors 模板操作中将选项传递给 ERB 模板引擎的方法。
我偶然发现了使用 thors 模板操作的 bundler cli 源,如下所示:
opts = {:name => name,
:constant_name => constant_name,
:constant_array => constant_array,
:author_name => author_name,
:author_email => author_email
}
template(File.join("newgem/Gemfile.tt"),
File.join(target, "Gemfile"),
opts)
但是当我在我的 thor 任务中添加这样的选项时,ERB 找不到它们,我只能在我的 thor 类中使用参数和函数来设置模板中的变量。
我不知道绑定在 ruby 中是如何工作的,也许有一种方法可以通过绑定到 ERB 来传递范围。