Commit 7b4075d5 by Timothée Peignier

improve less and sass compilers

parent 8fcaffdb
......@@ -112,6 +112,6 @@ A custom compiler for a imaginary compiler called jam ::
def match_file(self, filename):
return path.endswith('.jam')
def compile_file(self, content):
def compile_file(self, content, path):
return jam.compile(content)
......@@ -22,7 +22,7 @@ class Compiler(object):
new_path = self.output_path(path, compiler.output_extension)
content = self.read_file(path)
try:
compiled_content = compiler.compile_file(content)
compiled_content = compiler.compile_file(content, storage.path(path))
self.save_file(new_path, compiled_content)
except CompilerError:
if not storage.exists(new_path) or not settings.PIPELINE:
......@@ -53,7 +53,7 @@ class CompilerBase(object):
def match_file(self, filename):
raise NotImplementedError
def compile_file(self, content):
def compile_file(self, content, path):
raise NotImplementedError
def save_file(self, path, content):
......@@ -68,9 +68,11 @@ class CompilerError(Exception):
class SubProcessCompiler(CompilerBase):
def execute_command(self, command, content):
def execute_command(self, command, content=None):
pipe = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE,
stdin=subprocess.PIPE, stderr=subprocess.PIPE)
if content:
pipe.stdin.write(content)
pipe.stdin.close()
......
......@@ -8,6 +8,9 @@ class CoffeeScriptCompiler(SubProcessCompiler):
def match_file(self, path):
return path.endswith('.coffee')
def compile_file(self, content):
command = "%s -sc %s" % (settings.PIPELINE_COFFEE_SCRIPT_BINARY, settings.PIPELINE_COFFEE_SCRIPT_ARGUMENTS)
def compile_file(self, content, path):
command = "%s -sc %s" % (
settings.PIPELINE_COFFEE_SCRIPT_BINARY,
settings.PIPELINE_COFFEE_SCRIPT_ARGUMENTS
)
return self.execute_command(command, content)
import os
import tempfile
from pipeline.conf import settings
from pipeline.compilers import SubProcessCompiler
......@@ -11,20 +8,11 @@ class LessCompiler(SubProcessCompiler):
def match_file(self, filename):
return filename.endswith('.less')
def compile_file(self, content):
in_file, in_filename = tempfile.mkstemp()
in_file = os.fdopen(in_file, 'w+b')
in_file.write(content)
in_file.flush()
def compile_file(self, content, path):
command = '%s %s %s' % (
settings.PIPELINE_LESS_BINARY,
settings.PIPELINE_LESS_ARGUMENTS,
in_filename
path
)
content = self.execute_command(command, content)
in_file.close()
os.remove(in_filename)
content = self.execute_command(command)
return content
......@@ -8,8 +8,10 @@ class SASSCompiler(SubProcessCompiler):
def match_file(self, filename):
return filename.endswith('.scss')
def compile_file(self, content):
command = "%s --scss %s" % (settings.PIPELINE_SASS_BINARY, settings.PIPELINE_SASS_ARGUMENTS)
if self.verbose:
command += '--verbose'
return self.execute_command(command, content)
def compile_file(self, content, path):
command = "%s --scss %s %s" % (
settings.PIPELINE_SASS_BINARY,
settings.PIPELINE_SASS_ARGUMENTS,
path
)
return self.execute_command(command)
......@@ -10,7 +10,7 @@ class DummyCompiler(CompilerBase):
def match_file(self, path):
return path.endswith('.coffee')
def compile_file(self, content):
def compile_file(self, content, path):
return content
......
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