hawx / guard-sass

Guard::Sass automatically rebuilds sass files when modified (like sass --watch)
MIT License
88 stars 35 forks source link

Output file relative to the input file location #58

Closed brendon closed 8 years ago

brendon commented 8 years ago

Hi there, I've been hunting for a while but can't see a way to specify the output directory in relation to the location of the input file.

In my setup, we're watching .scss files for a bunch of different customer templates each in their own directory so:

customer 1
  - sass
customer 2
  - sass

I want the files in customer 1's sass directory to be output into the customer 1 directory.

Any tips would be appreciated :)

e2 commented 8 years ago

Hi @brendon,

you probably want to specify 2 separate guards for this, e.g.:

guard 'sass', :input => 'customer 1/sass', :output => 'customer 1'
guard 'sass', :input => 'customer 2/sass', :output => 'customer 2'
brendon commented 8 years ago

Hi @e2, thanks for that suggestion. Unfortunately the intermediate customer directories aren't known ahead of time. I.e. we'll be adding lots of them over time and would prefer not to have to update the guard file each time. They also won't have a predictable naming scheme; the names I used above are just for example.

Do you think there's still a way to do it provided those conditions?

e2 commented 8 years ago

@brendon - yes, if you had the same problem for e.g. coffeescript files, you'd use e.g. https://github.com/guard/guard-coffeescript

If you notice, that project allows patterns and such for output files. Ideally, I think you should copy the guard-coffeescript project, and change the CoffeeScript related to code to Sass.

Or, you can use something like https://github.com/guard/guard-yield to run any code when a file change and just run sass on it.

Probably in the future Guard will make it easier to define rules like this, so maybe I'll be updating it to support such rules out of the box, but I'm not the guard-sass maintainer - so it's not up to me to decide how guard-sass itself will work.

brendon commented 8 years ago

Thanks @e2, that's really helpful. I'll take a look at guard-coffeescript and and see if there's scope to also make a PR for this functionality into guard-sass. I'll leave this issue open in case I come up with a solution.

brendon commented 8 years ago

Hi @e2, I ended up using guard-yield. It was quite a simple solution in the end.