LessFilter (see lesscss.org)
Signed-off-by: Jannis Leidel <jannis@leidel.info>
This commit is contained in:
committed by
Jannis Leidel
parent
36fc377a2f
commit
c30e3fb339
@@ -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 = []
|
||||
|
||||
|
||||
31
compressor/filters/less.py
Normal file
31
compressor/filters/less.py
Normal 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
|
||||
Reference in New Issue
Block a user