# HG changeset patch # User Ludovic Chabant # Date 1427514451 25200 # Node ID d1490028e2111bf3a945a8c534c216b460ff07ba # Parent 1ddd18ad5e761c09c969133b45b214f54a329600 cleancss: Add option to specify an output extension, like `.min.css`. diff -r 1ddd18ad5e76 -r d1490028e211 piecrust/processing/compressors.py --- a/piecrust/processing/compressors.py Fri Mar 27 20:46:36 2015 -0700 +++ b/piecrust/processing/compressors.py Fri Mar 27 20:47:31 2015 -0700 @@ -3,21 +3,33 @@ import logging import platform import subprocess -from piecrust.processing.base import SimpleFileProcessor +from piecrust.processing.base import Processor, SimpleFileProcessor logger = logging.getLogger(__name__) -class CleanCssProcessor(SimpleFileProcessor): +class CleanCssProcessor(Processor): PROCESSOR_NAME = 'cleancss' def __init__(self): - super(CleanCssProcessor, self).__init__({'css': 'css'}) + super(CleanCssProcessor, self).__init__() self._conf = None - def _doProcess(self, in_path, out_path): + def matches(self, path): + return path.endswith('.css') + + def getOutputFilenames(self, filename): self._ensureInitialized() + basename, _ = os.path.splitext(filename) + return ['%s%s' % (basename, self._conf['out_ext'])] + + def process(self, path, out_dir): + self._ensureInitialized() + + _, in_name = os.path.split(path) + out_name = self.getOutputFilenames(in_name)[0] + out_path = os.path.join(out_dir, out_name) args = [self._conf['bin'], '-o', out_path] args += self._conf['options'] @@ -46,6 +58,9 @@ self._conf = self.app.config.get('cleancss') or {} self._conf.setdefault('bin', 'cleancss') self._conf.setdefault('options', ['--skip-rebase']) + self._conf.setdefault('out_ext', '.css') + if len(self._conf['out_ext']) > 0 and self._conf['out_ext'][0] != '.': + self._conf['out_ext'] = '.' + self._conf['out_ext'] if not isinstance(self._conf['options'], list): raise Exception("The `cleancss/options` configuration setting " "must be an array of arguments.")