【问题标题】:How can I "pipe" input from one guard to another?如何将输入从一名警卫“管道”到另一名警卫?
【发布时间】:2013-02-12 05:04:08
【问题描述】:

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

【问题讨论】:

    标签: guard


    【解决方案1】:

    使用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
    

    【讨论】:

      猜你喜欢
      • 2017-05-08
      • 2011-06-19
      • 1970-01-01
      • 1970-01-01
      • 2011-01-30
      • 1970-01-01
      • 2011-04-09
      • 1970-01-01
      • 2019-03-22
      相关资源
      最近更新 更多