Friday 29 June 2012

Using pyscss with django_compressor

I use django_compressor in every django project and so should you. However, one part of the deployment process that has always slowed me down was fiddling around with getting the sass gem installed to precompile. It’s no so bad to install if you have root access, but it you don’t (i.e. on webfaction) then it’s a fiddly process. In comparison installing pyscss is a charm –

 pip install pycss 

Once you’ve done that then all you need to do is tell django_compressor to preprocess all text/x-sass files with pyscss. Add this to your settings/local settings.py file –

 COMPRESS_PRECOMPILERS = (                                                                                                    ('text/x-sass', '/path/to/pyscss {infile} > {outfile}'),                                                )   

In this context the only difference between the scss gem and pyscss is that them gem takes an argument for an infile and outfile, where as pyscss takes only an infile and we redirect the output of pyscss to our outfile. In case you’re unfamiliar with redirection in unix/linux, the > arrow above in betweeen {infile} & {outfile}, that’s the redirection.