3 from django.conf import settings
5 from compress.filter_base import FilterBase, FilterError
7 BINARY = getattr(settings, 'COMPRESS_YUI_BINARY', 'java -jar yuicompressor.jar')
8 CSS_ARGUMENTS = getattr(settings, 'COMPRESS_YUI_CSS_ARGUMENTS', '')
9 JS_ARGUMENTS = getattr(settings, 'COMPRESS_YUI_JS_ARGUMENTS', '')
11 class YUICompressorFilter(FilterBase):
13 def filter_common(self, content, type_, arguments):
14 command = '%s --type=%s %s' % (BINARY, type_, arguments)
17 command += ' --verbose'
19 p = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stdin=subprocess.PIPE, stderr=subprocess.PIPE)
20 p.stdin.write(content)
23 filtered_css = p.stdout.read()
31 err = 'Unable to apply YUI Compressor filter'
33 raise FilterError(err)
40 def filter_js(self, js):
41 return self.filter_common(js, 'js', JS_ARGUMENTS)
43 def filter_css(self, css):
44 return self.filter_common(css, 'css', CSS_ARGUMENTS)