__init__.py 743 Bytes
Newer Older
1 2 3
import os
import tempfile

4
from pipeline.conf import settings
5
from pipeline.compilers import SubProcessCompiler
Timothée Peignier committed
6 7


8
class LessCompiler(SubProcessCompiler):
Timothée Peignier committed
9 10
    output_extension = 'css'

Timothée Peignier committed
11 12 13 14
    def match_file(self, filename):
        return filename.endswith('.less')

    def compile_file(self, content):
15 16 17 18 19 20 21 22 23
        in_file, in_filename = tempfile.mkstemp()
        in_file = os.fdopen(in_file, 'w+b')
        in_file.write(content)
        in_file.flush()

        command = '%s %s %s' % (
            settings.PIPELINE_LESS_BINARY,
            in_filename,
            settings.PIPELINE_LESS_ARGUMENTS
Timothée Peignier committed
24
        )
25
        content = self.execute_command(command, content)
Timothée Peignier committed
26

27 28
        in_file.close()
        os.remove(in_filename)
Timothée Peignier committed
29

30
        return content