我正在寻找一种方法来在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)
Run Code Online (Sandbox Code Playgroud)
但是当我在我的Thor任务中添加这样的选项时,ERB找不到它们,我只能在我的thor类中使用参数和函数来在模板中设置变量.
我不知道ruby中的绑定是如何工作的,也许有一种方法可以通过绑定到ERB来传递范围.