Commit d74aefe1 by Timothée Peignier

add coffee script compiler

parent 37641e12
import subprocess
class CompilerBase(object): class CompilerBase(object):
pass def __init__(self, verbose):
self.verbose = verbose
def match_file(self, filename):
raise NotImplementedError
def compile_file(self, content):
raise NotImplementedError
class CompilerError(Exception): class CompilerError(Exception):
pass pass
class SubProcessCompiler(CompilerBase):
def execute_command(self, command, content):
pipe = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE,
stdin=subprocess.PIPE, stderr=subprocess.PIPE)
pipe.stdin.write(content)
pipe.stdin.close()
compressed_content = pipe.stdout.read()
pipe.stdout.close()
error = pipe.stderr.read()
pipe.stderr.close()
if pipe.wait() != 0:
if not error:
error = "Unable to apply %s filter" % self.__class__.__name__
raise FilterError(error)
if self.verbose:
print error
return compressed_content
from compress.conf import settings
from compress.compilers import SubProcessCompiler
class CoffeeScriptCompiler(SubProcessCompiler):
def match_file(self, filename):
return filename.endswith('.coffee')
def compile_file(self, content):
command = "%s %s" % (settings.COFFEE_SCRIPT_BINARY, settings.COFFEE_SCRIPT_ARGUMENTS)
if self.verbose:
command += '--verbose'
return self.execute_command(command, content)
...@@ -35,6 +35,9 @@ COMPRESS_CLOSURE_ARGUMENTS = getattr(settings, 'COMPRESS_CLOSURE_ARGUMENTS', '') ...@@ -35,6 +35,9 @@ COMPRESS_CLOSURE_ARGUMENTS = getattr(settings, 'COMPRESS_CLOSURE_ARGUMENTS', '')
COMPRESS_UGLIFYJS_BINARY = getattr(settings, 'COMPRESS_UGLIFYJS_BINARY', '/usr/local/bin/uglifyjs') COMPRESS_UGLIFYJS_BINARY = getattr(settings, 'COMPRESS_UGLIFYJS_BINARY', '/usr/local/bin/uglifyjs')
COMPRESS_UGLIFYJS_ARGUMENTS = getattr(settings, 'COMPRESS_UGLIFYJS_ARGUMENTS', '-nc') COMPRESS_UGLIFYJS_ARGUMENTS = getattr(settings, 'COMPRESS_UGLIFYJS_ARGUMENTS', '-nc')
COMPRESS_COFFEE_SCRIPT_BINARY = getattr(settings, 'COMPRESS_COFFEE_SCRIPT_BINARY', '/usr/local/bin/coffee')
COFFEE_SCRIPT_ARGUMENTS = getattr(settings, 'COFFEE_SCRIPT_ARGUMENTS', '-sc')
if COMPRESS_CSS_COMPRESSORS is None: if COMPRESS_CSS_COMPRESSORS is None:
COMPRESS_CSS_COMPRESSORS = [] COMPRESS_CSS_COMPRESSORS = []
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment