Skip to content

Instantly share code, notes, and snippets.

@madssj
Last active August 29, 2015 13:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save madssj/8916641 to your computer and use it in GitHub Desktop.
Save madssj/8916641 to your computer and use it in GitHub Desktop.
Ngmin compressor mixin for django-pipeline
# edit: i put this in a project called django-pipeline-ngmin-mixin-compressor
# which you should use
from pipeline.conf import settings
from pipeline.compressors.yuglify import YuglifyCompressor
from pipeline.compressors.uglifyjs import UglifyJSCompressor
class NgminMixIn(object):
"""
A mixin class to spice up any pipeline compressor with running ngmin
bofore compressing the resulting javascript.
Requires the settings variables `PIPELINE_NGMIN_BINARY` and
`PIPELINE_NGMIN_ARGUMENTS` which should be self-explanatory.
Set `PIPELINE_JS_COMPRESSOR` to `path.to.compressors.NgminUglifyCompressor`
or roll your own.
"""
def compress_js(self, js):
if 'angular' not in js:
return super(NgminMixIn, self).compress_js(js)
command = "%s %s" % (
settings.PIPELINE_NGMIN_BINARY,
settings.PIPELINE_NGMIN_ARGUMENTS,
)
js = self.execute_command(command, js)
return super(NgminMixIn, self).compress_js(js)
class NgminYuglifyCompressor(NgminMixIn, YuglifyCompressor): pass
class NgminUglifyCompressor(NgminMixIn, UglifyJSCompressor): pass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment