0

我正在尝试警卫,我想使用 haml 编写车把模板。有没有办法将guard-haml的输出“管道”到guard-handlebars(即有2个警卫在同一个文件上操作)?或者,是否有可以同时执行这两个步骤的保护插件?

4

1 回答 1

0

使用guard-shell拼凑出一个解决方案。根本问题是guard-handlebars 期望它的输入文件以“.handlebars”结尾,并且没有配置选项可以改变它。我没有修补guard-handlebars,而是在guard-haml处理完文件后简单地使用guard-shell重命名文件。这是我的 Guardfile 中的结果代码:

guard 'haml', :input => 'src/templates', :output => 'public/js/templates/html' do
    watch %r{^.+(\.hbs\.haml)$}
end

guard :shell do
  watch %r{^public/js/templates/html/.+(\.hbs\.html)$} do |m|
    path = m[0]
    new_path = path.gsub(/\.hbs\.html$/, '.handlebars')
    `mv #{path} #{new_path}`
  end
end

guard 'handlebars', :input => 'public/js/templates/html', :output => 'public/js/templates' do
  watch %r{^.+(\.handlebars)$}
end
于 2013-02-11T21:04:08.807 回答