Pass the compressor class as the sender to the post_compress signal, not the rather generic string named 'django-compressor'.

This commit is contained in:
Jannis Leidel
2011-11-24 14:02:17 +01:00
parent bba941c341
commit fddd27aff0
4 changed files with 26 additions and 12 deletions

View File

@@ -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)

View File

@@ -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
------

View File

@@ -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
---------

View File

@@ -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']