A thin wrapper around the YUI Compressor
0
Updated over 10 years ago (13 Jun 2009 at 03:48 AM)
recent activity
In Brief | A very thin wrapper around the YUI Compressor. You must set the environmental variable YUICOMPRESSOR_JAR to the location of the YUI Compressor JAR file.... more |
Language | Python |
# 's
1'''
2Created on Jun 12, 2009
3
4@author: Stou
5'''
6
7import os
8from subprocess import Popen, PIPE
9
10def yuimin(js):
11 '''
12 Compress the given string using the
13 YUICompressor (syntax is identical to jsmin)
14 '''
15
16 proc = Popen(['java', '-jar', os.environ.get('YUICOMPRESSOR_JAR'), '--type', 'js'],
17 stdout=PIPE, stderr=PIPE, stdin=PIPE)
18 stdout, stderr = proc.communicate(input=js)
19
20 return str(stdout)
21
22def yuic_present():
23 '''
24 Check if the YUI Commpressor is present
25 '''
26
27 return os.environ.get('YUICOMPRESSOR_JAR') != None
A very thin wrapper around the YUI Compressor. You must set the environmental variable YUICOMPRESSOR_JAR to the location of the YUI Compressor JAR file.
Since the syntax is the same as for the jsmin method one can do:
# 's
1if yuic_present():
2 print 'Using YUI Compressor'
3 self.minifier = yuimin
4else:
5 print 'Using JSMIN'
6 self.minifier = jsmin
Add a Comment