lepture/python-livereload — pull request #14 by uniphil (2012-12-11 07:09:32+00:00)
Title: Add CoffeeScript Support

Compile coffeescript files similar to how you compile less or other compiled sources.

I added a class called `_StdinCompiler` which is very similar to `_CommandCompiler`, but gets files in and out via stdio instead of passing file names as arguments. This is because `coffee` does not let you choose the output file name when compiling (it just swaps *.coffee for *.js). Getting sources in and out via stdin mode allows us to write the files with python using arbitrary file names, so we can keep the same `Task(file, compiler(in, out))` pattern in the `Guardfile`.

`_StdinCompiler` is nearly identical to `_CommandCompiler`, but it 1) doesn't append a filename to the end of the command, 2) uses `Popen` with `stdin=PIPE` and 3) pipes in the input file when it calls `communicate()`. Maybe setting some kind of switch and three if statements in the body would yield lower code duplication, but it felt to hacky when I was writing it that way. I'm interested in feedback on my approach!