I have the following folder structure that i need to run compass watch
on:
| config.rb
| rakefile.rb
+---folder1
| +---css
| +---img
| +---js
| \---sass
|
+---folder2
| +---css
| +---img
| +---js
| \---sass
|
\---folder3
+---css
+---img
+---js
\---sass
I keep the config.rb outside because it all contains the same js, img, css folders config with the same :output
settings.
Here's my rakefile.rb to watch for all folders:
desc 'Compile folder1 sass'
task :watch_1 do
puts 'Watching folder1 sass...'
system 'compass watch --sass-dir folder1/sass --css-dir folder1/css -c config.rb'
end
desc 'Compile folder2 sass'
task :watch_2 do
puts 'Watching folder2 sass...'
system 'compass watch --sass-dir folder2/sass --css-dir folder2/css -c config.rb'
end
desc 'Compile folder3 sass'
task :watch_3 do
puts 'Watching folder3 sass...'
system 'compass watch --sass-dir folder3/sass --css-dir folder3/css -c config.rb'
end
# Watch all sass folder to compile css.
multitask :watch_all => [:watch_1, :watch_2, :watch_3] do
puts 'Watching all...'
end
My question is... How can i for loop and run the task in the rakefile.rb when i have new folder? I read around but i am stuck at creating the task. Here's my pseudo codes:
$folders = ['folder1', 'folder2', ... , 'folderN'];
foreach $folder in $folders do
system 'compass watch --sass-dir $folder/sass --css-dir $folder/css -c config.rb'
end
You can do it in ruby-way..by using "each" loop. For example:
Or using a block:
Is it the answer you were looking for?