diff --git a/compressor/base.py b/compressor/base.py index 2c01c70..f0e7bb8 100644 --- a/compressor/base.py +++ b/compressor/base.py @@ -266,6 +266,7 @@ class Compressor(object): self.context['compressed'].update(context or {}) self.context['compressed'].update(self.extra_context) final_context = Context(self.context) + post_compress.send(sender=self.__class__, type=self.type, mode=mode, context=final_context) return render_to_string("compressor/%s_%s.html" % (self.type, mode), final_context) diff --git a/docs/changelog.txt b/docs/changelog.txt index 304bcc0..1029769 100644 --- a/docs/changelog.txt +++ b/docs/changelog.txt @@ -38,6 +38,10 @@ v1.2.0 if the YUI compressor is shipped as a script like ``/usr/bin/yui-compressor``. +- Changed the sender parameter of the :func:`~compressor.signals.post_compress` + signal to be either :class:`compressor.css.CssCompressor` or + :class:`compressor.js.JsCompressor` for easier customization. + v1.1.1 ------ diff --git a/docs/usage.txt b/docs/usage.txt index 83a005b..9376345 100644 --- a/docs/usage.txt +++ b/docs/usage.txt @@ -165,7 +165,14 @@ you need the exact filenames for use in an HTML5 manifest file. The signal sends the following arguments: ``sender`` - Always "django-compressor". + Either :class:`compressor.css.CssCompressor` or + :class:`compressor.js.JsCompressor`. + + .. versionchanged:: 1.2 + + The sender is now one of the supported Compressor classes for + easier limitation to only one of them, previously it was a string + named ``'django-compressor'``. ``type`` Either "``js``" or "``css``". @@ -177,21 +184,23 @@ sends the following arguments: The context dictionary used to render the output of the compress template tag. - If ``mode`` is "``file``", this will contain a "``url``" key that maps to - the relative URL for the compressed asset. + If ``mode`` is "``file``" the dictionary named ``compressed`` in the + context will contain a "``url``" key that maps to the relative URL for + the compressed asset. - If ``type`` is "``css``", the context will additionally contain a - "``media``" key with a value of ``None`` if no media attribute is specified on - the link/style tag and equal to that attribute if one is specified. + If ``type`` is "``css``", the dictionary named ``compressed`` in the + context will additionally contain a "``media``" key with a value of + ``None`` if no media attribute is specified on the link/style tag and + equal to that attribute if one is specified. - Additionally, ``context['name']`` will be the third positional argument to - the template tag, if provided. + Additionally, ``context['compressed']['name']`` will be the third + positional argument to the template tag, if provided. .. note:: When compressing CSS, the ``post_compress`` signal will be called once for - every different media attribute on the tags within the ``{% compress %}`` tag - in question. + every different media attribute on the tags within the ``{% compress %}`` + tag in question. CSS Notes --------- diff --git a/tests/tests/signals.py b/tests/tests/signals.py index 04a60d3..c9801d7 100644 --- a/tests/tests/signals.py +++ b/tests/tests/signals.py @@ -34,7 +34,7 @@ class PostCompressSignalTestCase(TestCase): post_compress.connect(callback) self.js_node.output() args, kwargs = callback.call_args - self.assertEquals('django-compressor', kwargs['sender']) + self.assertEquals(JsCompressor, kwargs['sender']) self.assertEquals('js', kwargs['type']) self.assertEquals('file', kwargs['mode']) context = kwargs['context'] @@ -47,7 +47,7 @@ class PostCompressSignalTestCase(TestCase): post_compress.connect(callback) self.css_node.output() args, kwargs = callback.call_args - self.assertEquals('django-compressor', kwargs['sender']) + self.assertEquals(CssCompressor, kwargs['sender']) self.assertEquals('css', kwargs['type']) self.assertEquals('file', kwargs['mode']) context = kwargs['context']