Last active
August 29, 2015 13:56
-
-
Save madssj/8916641 to your computer and use it in GitHub Desktop.
Ngmin compressor mixin for django-pipeline
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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