diff --git a/compressor/base.py b/compressor/base.py index 4c36359..2c01c70 100644 --- a/compressor/base.py +++ b/compressor/base.py @@ -258,13 +258,14 @@ class Compressor(object): Renders the compressor output with the appropriate template for the given mode and template context. """ - if context is None: - context = {} - final_context = Context() - final_context.update(self.context) - final_context.update(context) - final_context.update(self.extra_context) - post_compress.send(sender='django-compressor', type=self.type, + # Just in case someone renders the compressor outside + # the usual template rendering cycle + if 'compressed' not in self.context: + self.context['compressed'] = {} + + self.context['compressed'].update(context or {}) + self.context['compressed'].update(self.extra_context) + final_context = Context(self.context) mode=mode, context=final_context) return render_to_string("compressor/%s_%s.html" % (self.type, mode), final_context) diff --git a/compressor/templates/compressor/css_file.html b/compressor/templates/compressor/css_file.html index e27821b..2b3a86f 100644 --- a/compressor/templates/compressor/css_file.html +++ b/compressor/templates/compressor/css_file.html @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/compressor/templates/compressor/css_inline.html b/compressor/templates/compressor/css_inline.html index ae64fa6..86c3d8f 100644 --- a/compressor/templates/compressor/css_inline.html +++ b/compressor/templates/compressor/css_inline.html @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/compressor/templates/compressor/js_file.html b/compressor/templates/compressor/js_file.html index bfa2b59..09d6a9b 100644 --- a/compressor/templates/compressor/js_file.html +++ b/compressor/templates/compressor/js_file.html @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/compressor/templates/compressor/js_inline.html b/compressor/templates/compressor/js_inline.html index 586bd93..403bec5 100644 --- a/compressor/templates/compressor/js_inline.html +++ b/compressor/templates/compressor/js_inline.html @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/compressor/templatetags/compress.py b/compressor/templatetags/compress.py index 4f533c7..8c4c3d3 100644 --- a/compressor/templatetags/compress.py +++ b/compressor/templatetags/compress.py @@ -81,10 +81,13 @@ class CompressorNode(template.Node): return cached_offline # Prepare the compressor - context.update({'name': self.name}) + if 'compressed' in context: + raise template.TemplateSyntaxError("A context variable named " + "'compresse' was found in the context. Make sure to name " + "it differently as this name is reserved to Compressor.") + context['compressed'] = {'name': self.name} compressor = self.compressor_cls(content=self.nodelist.render(context), context=context) - # Check cache cache_key, cache_content = self.render_cached(compressor, forced) if cache_content is not None: diff --git a/docs/changelog.txt b/docs/changelog.txt index 804c999..304bcc0 100644 --- a/docs/changelog.txt +++ b/docs/changelog.txt @@ -1,9 +1,38 @@ Changelog ========= -v1.1.2 +v1.2.0 ------ +- Introduced a new ``compressed`` context dictionary that is passed to + the templates that are responsible for rendering the compressed snippets. + + This is a **backwards-incompatible change** if you've overridden any of + the included templates: + + - ``compressor/css_file.html`` + - ``compressor/css_inline.html`` + - ``compressor/js_file.html`` + - ``compressor/js_inline.html`` + + The variables passed to those templates have been namespaced in a + dictionary, so it's easy to fix your own templates. + + For example, the old ``compressor/js_file.html``:: + + + + The new ``compressor/js_file.html``:: + + + +- Removed old templates named ``compressor/css.html`` and + ``compressor/js.html`` that were originally left for backwards + compatibility. If you've overridden them, just rename them to + ``compressor/css_file.html`` or ``compressor/js_file.html`` and + make sure you've accounted for the backwards incompatible change + of the template context mentioned above. + - Reverted an unfortunate change to the YUI filter that prepended ``'java -jar'`` to the binary name, which doesn't alway work, e.g. if the YUI compressor is shipped as a script like diff --git a/tests/tests/signals.py b/tests/tests/signals.py index 942a79d..04a60d3 100644 --- a/tests/tests/signals.py +++ b/tests/tests/signals.py @@ -38,7 +38,7 @@ class PostCompressSignalTestCase(TestCase): self.assertEquals('js', kwargs['type']) self.assertEquals('file', kwargs['mode']) context = kwargs['context'] - assert 'url' in context + assert 'url' in context['compressed'] def test_css_signal_sent(self): def listener(sender, **kwargs): @@ -51,7 +51,7 @@ class PostCompressSignalTestCase(TestCase): self.assertEquals('css', kwargs['type']) self.assertEquals('file', kwargs['mode']) context = kwargs['context'] - assert 'url' in context + assert 'url' in context['compressed'] def test_css_signal_multiple_media_attributes(self): css = """\ diff --git a/tests/tests/templatetags.py b/tests/tests/templatetags.py index 0f627e1..5e329bb 100644 --- a/tests/tests/templatetags.py +++ b/tests/tests/templatetags.py @@ -121,4 +121,4 @@ class TemplatetagTestCase(TestCase): render(template) args, kwargs = callback.call_args context = kwargs['context'] - self.assertEqual('foo', context['name']) + self.assertEqual('foo', context['compressed']['name'])