LessFilter (see lesscss.org)

Signed-off-by: Jannis Leidel <jannis@leidel.info>
This commit is contained in:
Maciek Szczesniak
2009-12-29 07:17:44 +01:00
committed by Jannis Leidel
parent 36fc377a2f
commit c30e3fb339
2 changed files with 33 additions and 0 deletions

View File

@@ -11,6 +11,8 @@ COMPRESS = getattr(settings, 'COMPRESS', not settings.DEBUG)
COMPRESS_CSS_FILTERS = getattr(settings, 'COMPRESS_CSS_FILTERS', ['compressor.filters.css_default.CssAbsoluteFilter'])
COMPRESS_JS_FILTERS = getattr(settings, 'COMPRESS_JS_FILTERS', ['compressor.filters.jsmin.JSMinFilter'])
COMPRESS_LESSC_BINARY = getattr(settings, 'COMPRESS_LESSC_BINARY', 'lessc')
if COMPRESS_CSS_FILTERS is None:
COMPRESS_CSS_FILTERS = []

View File

@@ -0,0 +1,31 @@
import os
import warnings
import tempfile
from compressor.conf import settings
from compressor.filters import FilterBase, FilterError
warnings.simplefilter('ignore', RuntimeWarning)
class LessFilter(FilterBase):
def output(self, **kwargs):
tmp_file = tempfile.NamedTemporaryFile(mode='w+b')
tmp_file.write(self.content)
tmp_file.flush()
output_file = tempfile.NamedTemporaryFile(mode='w+b')
command = '%s %s %s' % (settings.COMPRESS_LESSC_BINARY, tmp_file.name, output_file.name)
command_output = os.popen(command).read()
filtered_css = output_file.read()
output_file.close()
tmp_file.close()
if self.verbose:
print command_output
return filtered_css