我希望我的大多数项目都有一个单一的配置。在那里它会在我的项目文件夹中搜索任何sass,haml或sass文件夹。当我添加一个新位置来制作sass文件时,我不想更新配置。
开始文件夹结构
- sass
- test.sass
- coffee
- test.coffee
- haml
- test.html.haml
- a
- folder
- somewhere
- deep
- sass
- test2.sass
- coffee
- test2.coffee
- haml
- test2.html.haml
- Guardfile包含生成的文件和文件夹的所需文件夹结构:
- sass
- test.sass
- css
- test.css
- coffee
- test.coffee
- js
- test.js
- haml
- test.html.haml
- test.html
- a
- folder
- somewhere
- deep
- sass
- test2.sass
- css
- test2.css
- coffee
- test2.coffee
- js
- test2.js
- haml
- test2.html.haml
- test2.html
- Guardfile到目前为止,haml与
guard :haml, input: 'haml' do
watch(/^.+(\.html\.haml)$/)
end和sass,coffeescript使用完全相同的代码以不同的方式工作
guard :coffeescript, input: 'coffee', output: 'js' do
watch(/^.+(\.coffee)$/)
end
guard :sass, input: 'sass', output: 'css' do
watch(/^.+(\.sass)$/)
end最终结果是将目标css和js文件夹放在projectfolder的根目录下。即使我删除了output:属性,它也会在根目录创建一个make and sass文件夹。
结果文件夹结构
- sass
- test.sass
- css
- test.css
- test2.css
- coffee
- test.coffee
- js
- test.js
- test2.js
- haml
- test.html.haml
- test.html
- a
- folder
- somewhere
- deep
- sass
- test2.sass
- coffee
- test2.coffee
- haml
- test2.html.haml
- test2.html
- Guardfile我不知道这是怎么回事,有人能告诉我吗?
使用Guard版本2.6.1
发布于 2014-12-17 17:07:34
每个插件都有自己关于如何解释/使用目录的想法。
在coffeescript中,有一个“技巧”可以告诉它输出目录,方法是将输入目录部分放在regexp组中,例如:
guard :coffeescript, input: 'coffee', output: 'js' do
watch(/^(.+)\\.coffee$/)
end但我猜这会创建js/a/folder/somewhere/deep,而你想要a/folder/somewhere/deep/js。
如果你不指定输出目录,你可能会得到:a/folder/somewhere/deep -它很接近,但是在最后没有/js/文件夹。
实际上,Haml文件是不同的,因为虽然您希望(...)coffee/test2.coffee以(...)/js/test2.js的形式结束,但您希望(...)/haml/test2.html.haml以(...)/test2.html.haml的形式结束,而不是(...)/html/test2.html.haml (意思是:您不希望它位于html子文件夹中-我同意这将是愚蠢的)……
..。这意味着guard-haml是你所期望的其他插件中的例外。
所以这个短篇故事是:
您不能期望guard-coffeescript和guard-sass的行为像guard-haml, because at the same time you're expecting them to *not* behave the same way (nohtmloutput folder for.haml`文件-这显然是可以理解的)。
在haml中,工作方式如您所愿,只是因为您没有为它提供:output选项(尝试一下,看看会发生什么)。
同时,guard-coffeescript已经(由我)更新为使用较新版本的guard,因此模板现在有点不同,您可能需要:
input_dir = 'a/folder/somewhere/deep'
coffeescript_options = {
input: "#{input_dir}/coffee,
output: "#{input_dir}/js",
patterns: [%r{^#{input_dir}/(.+\.(?:coffee|coffee\.md|litcoffee))$}]
}
guard 'coffeescript', coffeescript_options do
coffeescript_options[:patterns].each { |pattern| watch(pattern) }
endguard-sass尚未针对更新版本的Guard进行更新(事实上,它从未迁移到Guard2.0),因此我甚至不会费心去研究它。
我看到的选择是:
因为Guardfile是纯ruby的,所以你可以选择迭代--如果这有帮助的话,例如:
# I don't know which parts of the structure are projects, so I'm guessing it's the first part
Dir[*].each do |project|
next unless File.directory?(project)
next if %w(sass css coffee js).include?(project) #(skip top level non-project folders)
input_dir = "#{project}/a/folder/somewhere/deep"
coffeescript_options = {
input: "#{input_dir}/coffee,
output: "#{input_dir}/js",
patterns: [%r{^#{input_dir}/(.+\.(?:coffee|coffee\.md|litcoffee))$}]
}
guard 'coffeescript', coffeescript_options do
coffeescript_options[:patterns].each { |pattern| watch(pattern) }
end
# guard 'sass' would go here with a similar setup
endhttps://stackoverflow.com/questions/25280480
复制相似问题