【发布时间】:2011-06-27 19:43:00
【问题描述】:
我正在寻找一种在 thors 模板操作中将选项传递给 ERB 模板引擎的方法。
我偶然发现了捆绑器 cli 源,其中使用了 thors 模板操作,如下所示:
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 来传递范围。
【问题讨论】:
-
您在 Thor 文件中尝试的哪些代码不起作用?
-
我确实复制了上面的代码,但它没有捕捉到传递的选项。