License Public Domain
Lines 23
Keywords
jsmin (1) minification (1) YUI Compressor (1)
Permissions
Owner: Stou S.
Viewable by Everyone
Editable by All Siafoo Users
Hide
Writing an article is easy - try our reStructured Text demo Join Siafoo Now or Learn More

A thin wrapper around the YUI Compressor Atom Feed 0

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
# '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